471,598 Members | 1,224 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,598 software developers and data experts.

Painting and zooming

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 );
}

Dec 4 '05 #1
2 3377
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.

"Frans Vander Meiren" <Fr***************@discussions.microsoft.com> wrote in
message news:3E**********************************@microsof t.com...
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 );
}

Dec 4 '05 #2
Thanks Bob. It works ...

"Bob Powell [MVP]" wrote:
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.

"Frans Vander Meiren" <Fr***************@discussions.microsoft.com> wrote in
message news:3E**********************************@microsof t.com...
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 );
}


Dec 4 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Harry_Crow | last post: by
reply views Thread by Gopi | last post: by
4 posts views Thread by Bernie Yaeger | last post: by
4 posts views Thread by =?Utf-8?B?U3BlZWR5?= | last post: by
2 posts views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.