Zoom at PictureBox
I have a Picture box at dock in parent container . And I want to create a button that it can zoom the picture in the PictureBox and unzoom it !!! have anyone any idea or a tutorial that it could help me ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hemant SrivastavaPosted Nov 20, 2013, 4:04 PM
private void trackBar1_Scroll(object sender, EventArgs e)
{
double zoomlevel = 1+ trackBar1.Value * 0.1;
ZoomIN(zoomlevel);
}
private void ZoomIN(double zoomLevel)
{
System.Drawing.Rectangle screenSize = new System.Drawing.Rectangle();
screenSize.Width = SystemInformation.VirtualScreen.Width;
screenSize.Height = SystemInformation.VirtualScreen.Height;
//int zoomFactor = 10;
Image img = pictureBox1.Image;
Bitmap bitMapImg = new Bitmap(img);
if (bitMapImg.Width < screenSize.Width && bitMapImg.Height < screenSize.Height)
{
Size newSize = new Size((int)(bitMapImg.Width * zoomLevel), (int)(bitMapImg.Height * zoomLevel));
Bitmap bmp = new Bitmap(bitMapImg, newSize);
pictureBox1.Image = (Image)bmp;
}
}
Hemant SrivastavaPosted Nov 20, 2013, 9:21 PM
Nikos RakPosted Nov 20, 2013, 5:15 PM
Hemant SrivastavaPosted Nov 20, 2013, 5:12 PM
I proposed the "Preserving" solution for Unzoom thinking that you mean 'Unzoom' is removing zoom completly at once.
Nikos RakPosted Nov 20, 2013, 5:01 PM
Hemant SrivastavaPosted Nov 20, 2013, 4:57 PM
Hemant SrivastavaPosted Nov 20, 2013, 4:55 PM
Nikos RakPosted Nov 20, 2013, 4:09 PM
Nikos RakPosted Nov 20, 2013, 3:56 PM
Hemant SrivastavaPosted Nov 20, 2013, 3:54 PM
Nikos RakPosted Nov 20, 2013, 3:48 PM
Hemant SrivastavaPosted Nov 20, 2013, 10:15 AM
private void btn_ZoomIN_Click(object sender, EventArgs e)
{
System.Drawing.Rectangle screenSize = new System.Drawing.Rectangle();
screenSize.Width = SystemInformation.VirtualScreen.Width;
screenSize.Height = SystemInformation.VirtualScreen.Height;
int zoomFactor = 10;
Image img = pictureBox1.Image;
Bitmap bitMapImg = new Bitmap(img);
if (bitMapImg.Width < screenSize.Width && bitMapImg.Height < screenSize.Height)
{
Size newSize = new Size((int)(bitMapImg.Width * zoomFactor), (int)(bitMapImg.Height * zoomFactor));
Bitmap bmp = new Bitmap(bitMapImg, newSize);
pictureBox1.Image = (Image)bmp;
}
}
Note: But to see zooming, you need to add scrollbar on your picture Box.
To get scroll bar on Picture Box:
Place your PictureBox into Panel.
Set 'SizeMode' property of PictureBox to "AutoSize"