Painting and zooming

G

Guest

Hi

Via an adapted Paint-method I try to zoom in on a part of a bitmap (8 x 8
pixels). So I defined the source rectangle of the image and the destination
rectangle on my application form (see code). That works well, but the pixels
of the first row and the first column are only rendered for half the size.
Can anyone explain that ...?

Thx
Frans


protected override void OnPaint(PaintEventArgs e)
{
// destination rectangle
Rectangle rectDst = new Rectangle();

rectDst.X = 0;
rectDst.Y = 0;
rectDst.Width = 320;
rectDst.Height = 320;

// source rectangle
Rectangle rectSrc = new Rectangle();

rectSrc.X = 0;
rectSrc.Y = 0;
rectSrc.Width = 8;
rectSrc.Height = 8;

// draw (part of the image)
Graphics g = e.Graphics;
g.InterpolationMode = InterpolationMode.NearestNeighbor ;
g.DrawImage( Bm, rectDst, rectSrc, GraphicsUnit.Pixel );
}
 
B

Bob Powell [MVP]

G

Guest

Thanks Bob. It works ...

Bob Powell said:
This is a common problem. Set the PixelOffsetMode to half.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top