473,396 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3436
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Harry_Crow | last post by:
I'm painting in the Non Client area of the control. I'm facing some flicker problem. Is it possible to achive Double buffer painting in Non Client area. The SetStyle with...
10
by: Deano | last post by:
I think that just about sums it up. Is there a fix/workaround for this?It's quite annoying behaviour and not user-friendly.thanksMartin
0
by: Gopi | last post by:
Hi All I have set a BackgroundImage for windows forms and i need to implement the image zooming feature for the form ie when ever i m zooming in or zooming out the form the corrosponding...
4
by: Bernie Yaeger | last post by:
I'd like to allow the user to zoom a window using a trackbar, say from 80% to 120% the size of the original window. I'm trying to do this with the following code, but it fails pretty miserably:...
0
by: gerstla | last post by:
hi I am building a simple control to view images with zooming capabilities. i want the image to zoom when it is clicked on. after zooming i want the control to try and move the point clicked to the...
0
by: pavanjosh | last post by:
Hello Frineds, Can anyone please help me in getting the code or library for written in C# for zooming in and zooming out the images in the picture box? Or is there any other way from which i can...
4
by: =?Utf-8?B?U3BlZWR5?= | last post by:
Hi there, I am currently writing an application where one inspects images and annotates certain features. Thus, one has to zoom in (4x) and pan around. The features are marked with little red...
0
by: johot | last post by:
I am currently creating a little photo application. In this application the user is able to zoom in the image and after zooming panning around inside the zoomed image with the mouse. The strange...
4
by: Marina Levit | last post by:
I am trying to do some processing on a background thread while keeping the UI painting. However, this is a generic server side call routine - and it needs to block until the server side call...
4
by: alarock | last post by:
how can i do Zooming of a particular area using OnMouseWheel (that is zooming a mouse wheel point that should come into view with zoom ) using C# Regards, ALGATES
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.