Archived

This topic is now archived and is closed to further replies.

What am I doing wrong (draw on scaled image)

This topic is 5241 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have posted to numerous forums (including two on this board) but no so far nothing. All I want to do is zoom out on an image (make it smaller), then draw a line on it that is the correct size and location. Currently, if the image is shown as full size, everything works just great, but if I zoom first, then try to draw a line, the line is too small, and it is not drawn where it should be. Here is exactly what I am doing now. Maybe some kind soul will be able to tell me the error of my ways. 1) I get the user click points and save them off. These points are relative to the screen, and will be adjusted back to the image which is at 0,0. For example, if the user clicks at 328, 54, that will be 0,0 on the image. 2) I create a line object using the points from the screen. For an example, say 328, 54, 687, 54 (a straight line across the top of the image that is 360 pixels wide). 3) I then call a method that first does a translate like this (in Java): Graphics2D g2D = gti.getGraphics2D(); g2D.translate(transformPointX, transformPointY); For this example, the transformPointX = 328, and Y = 54 (the same as the click point) 4) The method then does a scale. For this example, the scale is 100%, so no change is made. 5) The method then shifts the line to be drawn by adjusting the begin and end points. The formula for the adjustment is like this: newX = oldX - (view width / 2) - (image width / 2) newY = oldY - (view height / 2) - (image height / 2) For this example, it works just fine. Now let me explain what happens when I zoom in to 90% of the image size. First off, the line that I drew when the image was 100%, is scaled correctly, and in the position you would expect to see it in (across the top). Going through the same steps again 1) The click points are saved off (the begin point is 346, 77, the end point is 669, 77). 2) The line object is created using the points I just mentioned. 3) I then call a method that first does a translate like this (in Java): Graphics2D g2D = gti.getGraphics2D(); g2D.translate(transformPointX, transformPointY); For this example, the transformPointX = 346, and Y = 77 (like the click point) 4) The method then does a scale. For this example, the scale is 90%. It does it like this: g2D.scale(zoom, zoom); where zoom = 0.90 5) Then the points of the line get reset by subtracting using the formula I gave above (the view area - the ORIGINAL image size) I''d be happy to share code again, but there is a fair amount of it. Here is an image of what is happening though.
______________________________ 100
 ___________________________   90
   _______________________     80
     ___________________       70
       _______________         60 
         ___________           40
           _______             30
             ___               20
              _                10

 
So, if you started at 100%, drew a line across the top, then went to 90%, tried to a line across the top, then when the draw took place you would see the screen looking like what it does as the 90 with the line at the 100 as well. If you then zoomed out again to 80% and tried to draw a line across the top, you would see the line at the 80, the 90 and the 100. If you do this all the way to 10%, then you would see what I have above. If someone could explain to me what it is I''m doing wrong I''d really apprecite it. Thanks.

Share this post


Link to post
Share on other sites
quote:
Original post by darrinps
So, if you started at 100%, drew a line across the top, then went to 90%, tried to a line across the top, then when the draw took place you would see the screen looking like what it does as the 90 with the line at the 100 as well. If you then zoomed out again to 80% and tried to draw a line across the top, you would see the line at the 80, the 90 and the 100. If you do this all the way to 10%, then you would see what I have above.



Sounds to me like you''re tragically overcomplicating the problem, because if I''m understanding your problem right, this quote is the only important part of your post.

I''ll explain it like this. Imagine you took out a piece of paper, and drew your hand on it, actual size (100% scale). Good, everything works okay. Now, if I''m instructing you exactly as your program instructs the computer, the next step is for you to draw your hand smaller (90% scale) That means you''ve done two things. Drawn your hand normal, and then again slightly smaller. If you were to look at your paper, you''d see exactly the same problem you''re having in your program. That is to say, you never erase what happened before. Simplest solution: fill the old shape with the background color, THEN perform the same operation.

I''m really sorry if I''m not answering your question, but frankly you seem to describe two seperate problems. I admit my solution doesn''t really answer this:

quote:
Original post by darrinps
Currently, if the image is shown as full size, everything works just great, but if I zoom first, then try to draw a line, the line is too small, and it is not drawn where it should be.



I''d try to answer that too, but your lengthy description and the section I already quoted seem to point toward a different problem, so I have no idea what to look at there.

-Arek the Absolute

Share this post


Link to post
Share on other sites