Results 1 to 2 of 2
- 02-22-2012, 12:58 AM #1
Graphics2D.drawImage(...) always blits from top left?
I'm using Graphics2D to copy a portion of an image onto itself. This works fine when the source rectangle and the target rectangle do not overlap, or when applying a transform with a negative Y translation. But if the rectangles overlap and the Y translation is positive, then a portion of the source image is copied repeatedly. It seems that drawImage(...) always blits from the top left to the bottom right. This remains true even if I use the drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) version and reverse the coordinates.
My solution was to test for overlapping negative translations and copy to a temp image and then back to the main image. But I'm just wondering if there's something I'm missing, some obscure trick to make drawImage(...) blit from the bottom right to the top left.Get in the habit of using standard Java naming conventions!
- 02-22-2012, 08:48 AM #2
Re: Graphics2D.drawImage(...) always blits from top left?
That was the first thing that came to my mind when I read your subject line, even before I went through the post. Whether you use a temporary image or just a raster, you're going to have to cache your pixel data before it's overwritten with new content.My solution was to test for overlapping negative translations and copy to a temp image and then back to the main image.
IMO any code to reverse the blit would (1) be cumbersome to maintain, being so to speak contra-instinctive for the average 2D programmer but more important (2) wouldn't you just be transferring the same problem to the top left corner?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
NullPointerException on Graphics.drawImage
By Jaeela in forum New To JavaReplies: 5Last Post: 10-05-2011, 02:36 AM -
DrawImage with transparency ?
By mrhid6 in forum AWT / SwingReplies: 2Last Post: 10-01-2011, 11:58 PM -
drawImage im 13 plz help
By pseudohawtcakes in forum New To JavaReplies: 3Last Post: 05-17-2011, 08:07 PM -
Reversing dojo slider to make it slide from right to left rather left to right as giv
By gurpreet.singh in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 05-05-2011, 01:49 PM -
square moves left and down but not up or left
By natdizzle in forum AWT / SwingReplies: 3Last Post: 02-04-2011, 05:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks