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.
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?