Results 1 to 2 of 2
  1. #1
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default 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!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Graphics2D.drawImage(...) always blits from top left?

    My solution was to test for overlapping negative translations and copy to a temp image and then back to the main image.
    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.

    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?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. NullPointerException on Graphics.drawImage
    By Jaeela in forum New To Java
    Replies: 5
    Last Post: 10-05-2011, 02:36 AM
  2. DrawImage with transparency ?
    By mrhid6 in forum AWT / Swing
    Replies: 2
    Last Post: 10-01-2011, 11:58 PM
  3. drawImage im 13 plz help
    By pseudohawtcakes in forum New To Java
    Replies: 3
    Last Post: 05-17-2011, 08:07 PM
  4. 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 JSTL
    Replies: 1
    Last Post: 05-05-2011, 01:49 PM
  5. square moves left and down but not up or left
    By natdizzle in forum AWT / Swing
    Replies: 3
    Last Post: 02-04-2011, 05:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •