473,657 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PictureBox Zoom Problem

I'm trying to read a bitmap and zoom in/out it on screen.
I wrote some code but it did not perform as I expect. The bitmap shift
1 pixel to the upper-left coner when zooming in/out button was clicked.
Please kindly help me to check if anything wrong with my code. Many
many thanks.

using System.Drawing;
using System.Drawing. Drawing2D;

// Click Browse to open bitmap file
private void buttonBrowse_Cl ick(object sender, EventArgs e)
{
if (DialogResult.O K ==
this.openFileDi alogBmpLocation .ShowDialog())
{
myBitmap = new
Bitmap(this.ope nFileDialogBmpL ocation.FileNam e);

this.pictureBox Bitmap.Image = myBitmap;
this.pictureBox Bitmap.Size = new Size(myBitmap.W idth,
myBitmap.Height );
}
}

// Click Zoom In to resize the bitmap
private void buttonZoomIn_Cl ick(object sender, EventArgs e)
{
if (this.pictureBo xBitmap.Image == null) return;
Size nSize = new Size( pictureBoxBitma p.Image.Width * 2,
pictureBoxBitma p.Image.Height * 2);
Image gdi = new Bitmap(nSize.Wi dth, nSize.Height);

Graphics ZoomInGraphics = Graphics.FromIm age(gdi);

ZoomInGraphics. InterpolationMo de =
InterpolationMo de.NearestNeigh bor;
ZoomInGraphics. DrawImage(pictu reBoxBitmap.Ima ge, new Rectangle(new
Point(0, 0), nSize), new Rectangle(new Point(0, 0),
pictureBoxBitma p.Image.Size), GraphicsUnit.Pi xel);
ZoomInGraphics. Dispose();

pictureBoxBitma p.Image = gdi;
pictureBoxBitma p.Size = gdi.Size;
}

Oct 26 '06 #1
4 12290
Try this:
http://msdn2.microsoft.com/en-us/library/ms229648.aspx

chanmm

"wasishinca r" <ad*********@gm ail.comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
I'm trying to read a bitmap and zoom in/out it on screen.
I wrote some code but it did not perform as I expect. The bitmap shift
1 pixel to the upper-left coner when zooming in/out button was clicked.
Please kindly help me to check if anything wrong with my code. Many
many thanks.

using System.Drawing;
using System.Drawing. Drawing2D;

// Click Browse to open bitmap file
private void buttonBrowse_Cl ick(object sender, EventArgs e)
{
if (DialogResult.O K ==
this.openFileDi alogBmpLocation .ShowDialog())
{
myBitmap = new
Bitmap(this.ope nFileDialogBmpL ocation.FileNam e);

this.pictureBox Bitmap.Image = myBitmap;
this.pictureBox Bitmap.Size = new Size(myBitmap.W idth,
myBitmap.Height );
}
}

// Click Zoom In to resize the bitmap
private void buttonZoomIn_Cl ick(object sender, EventArgs e)
{
if (this.pictureBo xBitmap.Image == null) return;
Size nSize = new Size( pictureBoxBitma p.Image.Width * 2,
pictureBoxBitma p.Image.Height * 2);
Image gdi = new Bitmap(nSize.Wi dth, nSize.Height);

Graphics ZoomInGraphics = Graphics.FromIm age(gdi);

ZoomInGraphics. InterpolationMo de =
InterpolationMo de.NearestNeigh bor;
ZoomInGraphics. DrawImage(pictu reBoxBitmap.Ima ge, new Rectangle(new
Point(0, 0), nSize), new Rectangle(new Point(0, 0),
pictureBoxBitma p.Image.Size), GraphicsUnit.Pi xel);
ZoomInGraphics. Dispose();

pictureBoxBitma p.Image = gdi;
pictureBoxBitma p.Size = gdi.Size;
}

Oct 26 '06 #2
Why you don't use simple methods?
Bitmap ZoomedBmp = new Bitmap(oldBmp, newWidth, newHeight);

Oct 26 '06 #3
Thank for your reply, but I think there is not much different between
my code and the Microsoft Example. We use the same methed to zoom the
image. I think the problem is from pictureBox. I try to set the padding
and margin to 0, but ths image still shift. Just dont know what's wrong
with the pictureBox. Is anyone know why?

chanmm wrote:
Try this:
http://msdn2.microsoft.com/en-us/library/ms229648.aspx

chanmm

"wasishinca r" <ad*********@gm ail.comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
I'm trying to read a bitmap and zoom in/out it on screen.
I wrote some code but it did not perform as I expect. The bitmap shift
1 pixel to the upper-left coner when zooming in/out button was clicked.
Please kindly help me to check if anything wrong with my code. Many
many thanks.

using System.Drawing;
using System.Drawing. Drawing2D;

// Click Browse to open bitmap file
private void buttonBrowse_Cl ick(object sender, EventArgs e)
{
if (DialogResult.O K ==
this.openFileDi alogBmpLocation .ShowDialog())
{
myBitmap = new
Bitmap(this.ope nFileDialogBmpL ocation.FileNam e);

this.pictureBox Bitmap.Image = myBitmap;
this.pictureBox Bitmap.Size = new Size(myBitmap.W idth,
myBitmap.Height );
}
}

// Click Zoom In to resize the bitmap
private void buttonZoomIn_Cl ick(object sender, EventArgs e)
{
if (this.pictureBo xBitmap.Image == null) return;
Size nSize = new Size( pictureBoxBitma p.Image.Width * 2,
pictureBoxBitma p.Image.Height * 2);
Image gdi = new Bitmap(nSize.Wi dth, nSize.Height);

Graphics ZoomInGraphics = Graphics.FromIm age(gdi);

ZoomInGraphics. InterpolationMo de =
InterpolationMo de.NearestNeigh bor;
ZoomInGraphics. DrawImage(pictu reBoxBitmap.Ima ge, new Rectangle(new
Point(0, 0), nSize), new Rectangle(new Point(0, 0),
pictureBoxBitma p.Image.Size), GraphicsUnit.Pi xel);
ZoomInGraphics. Dispose();

pictureBoxBitma p.Image = gdi;
pictureBoxBitma p.Size = gdi.Size;
}
Oct 27 '06 #4
I did not use this cuz I need to zoom it by nearest neighbor.
Thanks for your reply.
Alex wrote:
Why you don't use simple methods?
Bitmap ZoomedBmp = new Bitmap(oldBmp, newWidth, newHeight);
Oct 27 '06 #5

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

Similar topics

1
6456
by: Dave | last post by:
I would like to ask how to do the zoom function onto the image of the PictureBox ?
7
17459
by: Randy Vande Hei | last post by:
Does anyone know how to change the the GDI+ coordinate system like you used to be able to do in VB6 with the picturebox.scale method. The picturebox.scale method took an x,y point defining the upper left corner and a second x,y point defining the lower right corner. In VB6 the 0,0 location was the upper left like in GDI+, but I could at least reset it so I could use it with lat/lons. Basically all I want to do is be able to use the...
6
22387
by: Rich | last post by:
Hello, I am putting together a simple picture viewing program to view jpg. bmp pictures. I have the picturebox sizemode set to autosize. I have the picturebox in a pannel set to autoscroll, so if I get a picture that is larger than the width/height of the containing form (pannel, etc) I can scroll. But some of the pictures are like 5 megapixels and are just way too large for the screen. When I open this pic in Microsoft Photo Editor...
4
10553
by: Thiru .Net | last post by:
hi wagner, i have a doubt in panel control in windows application. i have a panel control wherein i have put a picturebox control. i show picture into picturbox control. now i need to zoom in and zoom out the picture in the picturebox control. the picturebox control is within panel(autoscroll is enabled true) scroll bars are enabled.
1
1787
by: Eric | last post by:
Hi, I'm writing a program that based on input will create a document. It is something simulair as a printing example. In MS Word when you click on the shown document you can zoom in and if you click again you'll zoom out again. This is what I would like to do as well. I draw the document in a bitmap, since all the information is drawn from a database and on the form it is shown in a picturebox.
3
22441
by: Andrzej | last post by:
I have a picturebox on my C# .NET form. The picturebox size mode is set to zoom. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the coordinates of the mouse over the PICTUREBOX, not the actual image underneath that (which is zoomed). i.e....
2
7822
by: Dravid | last post by:
Hello, I am putting together a simple picture viewing program to view jpg pictures. I have the picturebox autosize set to true. I dont have the picturebox in a pannel set to autoscroll, so if I get a picture that is larger than the width/height of the containing form (pannel, etc) I can't able to scroll. When I open this pic in Microsoft Photo Editor - it opens to 50% zoom by default. How can I set the zoom in my picturebox which is...
0
1334
by: =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post by:
i have a problem on placing an image inside a picturebox. My problem is that i have a picturebox with the SizeMode property as "Zoom", which i must have, but when i insert the image in the picturebox, the image is aligned to the center of the picturebox, not the left. Does someone knows how can i align an image, to the left of a picturebox with the SizeMode property as "Zoom"? My thanks in advanced Ricardo Furtado
4
3707
by: Jim McGivney | last post by:
In C# on Form1 I genetate an array of PictureBoxes and populate each with an image as seen in the code below. Later on I want to access a specific PictureBox to change its image, but I keep getting the error "The name 'PictureBox1' does not exist in the current context" The code I use to try to access the PictureBox is "PictureBox1.Image = HoldBitMap; " where kount is an integer. I know the answer is probably in using the Controls...
0
8427
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
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8626
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
7355
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
6178
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
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.