I create a program that zoom in/out an image.
But it doesn't zoom to the center.
My picture box is in a panel and code is:
Image newImage = Image.FromFile("view.jpg");
pictureBox1.Width = (int)(newImage.Size.Width / ZoomLevel);
pictureBox1.Height = (int)(newImage.Size.Height / ZoomLevel);
Bitmap img = new Bitmap(newImage,
(int)(newImage.Size.Width / ZoomLevel),
(int)(newImage.Size.Height / ZoomLevel));
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBox1.Image = img;
I uploaded a sample project here. plz download this
I use Visual Studio 2008, C#, .Net 3.5
thanks in advance.
I found the answer.
I Uploade it here (link doesn't work anymore )
it a sample project with drag and zoom on an image. :)
Reza's solution works really well, but is a little bit difficult to access because of registration being required. I have rewritten his code as a standalone control and am putting the code here for future reference.
All credit goes to Reza obviously.
I think it is because you change the size of the picturebox. it is centered but i can not see it because you always see all the picture.
try to remove the 2 rows the change the width and hight of the picturebox or set them to be constant like 1 or 2 or... if you want to it to be according to the picture:
first option:
second option: