all groups > dotnet drawing api > january 2007 >
You're in the

dotnet drawing api

group:

drawing a rectangle over an image


drawing a rectangle over an image katie
1/24/2007 9:55:58 PM
dotnet drawing api:
Hi, I'm trying to draw a rectangle around an image but for some reason for
the life of me I can't figure out why the rectangle is not drawn the same
width as the image any ideas?

using(Image newImage = GenerateBitmap())
{
Rectangle srcRect = new Rectangle(0,0, newImage.Width, newImage.Height);
GraphicsUnit units = GraphicsUnit.Pixel;

// Draw image to screen.
g.DrawImage(newImage,0, 0, srcRect, units);
Pen myPen = new Pen(Color.Red, 1);
g.DrawRectangle(myPen,srcRect);
}


Thanks

Re: drawing a rectangle over an image Bob Powell [MVP]
1/26/2007 4:26:24 PM
This is because the image doesn't have a declared resolution identical
to that of the screen.

Use DrawImageUnscaled or calculate the correct physical size from the
declared DPI.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
AddThis Social Bookmark Button