Jump to content
  • Advertisement
Sign in to follow this  
MindWipe

[.net] Getting a rectangle drawn correctly around an image

This topic is 4275 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

Sounds easy. But it's not. So I want to be able to zoom in on image, so I just scale them (I could use the scaleTransform but I prefer to do it manually). So here's the code:
   g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
   g.DrawRectangle(Pens.Black, imagePosX - 1, imagePosY - 1, scaledWidth + 2, scaledHeight + 2);
   g.DrawImage(regionImage, new Rectangle(imagePosX, imagePosY, scaledWidth, scaledHeight), -0.5f, -0.5f, ((float)regionImage.Width) - 0.5f, ((float)regionImage.Height) - 0.5f, GraphicsUnit.Pixel);
  

I want to draw regionImage with a rectangle around it. Now it works on some sizes on scaledWidth & scaledHeight. But not all, and that's frustrating. I think that should work. The reason I take the source image from -0.5f, -0.5f to width -0.5, height - 0.5f is because of the NearestNeighbour thing. I don't want the first row and column of pixels to be drawn with half the size. Here is what happens when scaledWidth & Height is 96 (same as the source image) Any ideas? And remember I want it to work with all different scaledWidths and Heights, so I can't just tweak it to work. /MindWipe

Share this post


Link to post
Share on other sites
Advertisement
Ok, progress.

So by setting the boarder rectangles width to scaledWidth + 1 and scaledHeight + 1 seems to work better, which is kinda logical (IIRC rectangles are often drawn like that?).

And by setting the src rect from 0,0 to regionImage.Width, regionImage.Height it will work on scales from 2.0 - 1/inf.

But now I get two problems on higher scales:



1. The pic begins at -0.5px, -0.5px
2. The border to the right and bottom. Probably due to 1. (?)

Ideas how I can do this in the way I want it. I'm doing a sort of paint program, so I need the pixels to begin at 0,0.

Thanks in advance,
MindWipe

UPDATE: Got it fixed by changing the wrap mode and doing some tweaking

[Edited by - MindWipe on October 7, 2006 8:02:29 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!