• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with Graphics2D.rotate()

 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have an image that we print out on 4 x 6 inch sticky labels (with a thermal printer). Now we can also print on some that are approximately 4 x 8 inches, but because there's a peel-off tab on one end, we're adding a bit of info to the label, and we need to send the image to the printer upside down, so I'm trying to use Graphics2D's rotate and translate methods to solve this.

For the original 4 x 6 version of the image, we have a BufferedImage from which we get a Graphics2D, and then we start drawing stuff onto it like so:



Nothing too crazy there. So, this BufferedImage gets written out to a file that can be requested by a user, and when it gets sent down to a web browser, it's loaded into an applet as a parameter (base 64 encoded, so the applet decodes that), and then the applet prints it out to the user's local printer. The original BufferedImage is 420 pixels tall, and for the new version, we're just adding 134 pixels to the length. On the applet side, the size of the Paper object is set, and I thought this might need to be changed, but apparently, if a longer image is sent to it, it prints it all out anyway:



So everything is fine, except we need the image rotated 180 degrees. To accomplish this, the last thing we call in the code that creates the image (on the server side) before we call the first drawRect you see above is this:



Remember that extraLengthForDockTab is 134 pixels, and yes, we added that onto the BufferedImage length, the call to clearRect, etc. So it prints upside down, and the bottom of the image now prints out first, and it starts all the way at the edge of the label. But if you look at the other end--the last part to come out of the printer where the top is--it doesn't reach all the way to the top (it needs to be shifted some 30+ pixels). So I thought that maybe the image just isn't long enough and I just need to add some filler onto the bottom to push it up a bit. I called drawString a few more times at the bottom (the first part to come out), but those extra lines don't seem to make it onto the image (so it doesn't get moved up or anything like that).

After reading up on the graphics stuff for rotate and translate, I tried tweaking it by both subtracting and adding a little:



At first I was trying larger amounts, but even numbers this small cause it to do something very strange, no matter whether I add or subtract: the image rotates YET AGAIN just by tweaking this call to translate! I have no clue how or why that happens, but when it does, I'm back to where I started. Any idea as to what is going on?
[ March 16, 2005: Message edited by: Stephen Huey ]
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps some pictures, diagrams, or just putting your complete code up would garner some responses. I can't keep all of what you've written in my head at once. Make it short with only pertinent information and people will help. i.e. No one needs to know you're using a thermal printer; only that your image is rotating extra times and getting off center.
 
reply
    Bookmark Topic Watch Topic
  • New Topic