473,597 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(PaintEv entArgs 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.Interpolation Mode = InterpolationMo de.NearestNeigh bor ;
g.DrawImage( Bm, rectDst, rectSrc, GraphicsUnit.Pi xel );
}

Dec 4 '05 #1
2 3450
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******** *************** ***********@mic rosoft.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(PaintEv entArgs 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.Interpolation Mode = InterpolationMo de.NearestNeigh bor ;
g.DrawImage( Bm, rectDst, rectSrc, GraphicsUnit.Pi xel );
}

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******** *************** ***********@mic rosoft.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(PaintEv entArgs 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.Interpolation Mode = InterpolationMo de.NearestNeigh bor ;
g.DrawImage( Bm, rectDst, rectSrc, GraphicsUnit.Pi xel );
}


Dec 4 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1556
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 ControlStyles.DoubleBuffer and ControlStyles.AllPaintinginWmPaint set to true only works for Client area painting, Please Help me if any one has some Idea. Thank you,
10
4378
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
1520
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 background image also needs to be zoomed in and zoomed out. the zoom factors ( zooming values are) 50%,100% and 150% how do i implement this? thanks in advance Gopi
4
3822
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: (from the form) Dim per As Decimal per = CDec(zoomit.Value) setzoom(Me, Me.Font, per) ' per is the current value of the trackbar as a
0
1300
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 center or at least be in view. The code I am using know for centering isnt working correctly. AutoScrollPosition = new Point((int)(currentPoint.X * _zoom), (int)(currentPoint.Y * _zoom)); currentPoint is the last place I clicked. thanks
0
1798
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 achieve the same task? Your help will be gretely appreciated. Thanks and Reagrds Pavan Joshi
4
10139
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 rectangles.The images are 2048x2048 pixels. It seems that I can find no efficient way to implement both zooming and panning. At present I have a panel with autoscroll set to true inside which there is
0
1611
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 thing is that the first zoom is really slow, and so is the first panning. So if you zoom into an image it will first take some time, and when trying to pan the image around things will be really choppy. However if i zoom into the image even more, and...
4
1860
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 completes. So the idea is, a server side call begins, it gets spun off on another thread to keep the UI painting - but, the code flow cannot return to the caller until the server side call completes, because the caller expects the data. The only way...
4
8563
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
7971
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8259
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6698
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3932
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1495
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1243
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.