I'm trying to properly Zoom in/out Image in PictureBox. I have this code.
private Image GridMap;
private double ZoomFactor = 1;
protected override void OnMouseWheel(MouseEventArgs e)
{
if (e.Delta > 0)
{
ZoomFactor*=1.2;
}
else if (e.Delta < 0 && ZoomFactor >1 )
{
ZoomFactor /= 1.2;
}
Size newSize = new Size((int)(GridMap.Width * ZoomFactor), (int)(GridMap.Height * ZoomFactor));
Bitmap bmp = new Bitmap(GridMap, newSize);
MainGrid.Image = bmp;
}
Where MainGrid is PictureBox where i want to zoom.
This code works, but very slow after scrolling I wait 1-2seconds and then it shows the zoomed picture. with (800,800) image. Which is very slow.
I think I know why. Its copying resized bitmap instead of using just part of old one, but I don't know how to do it.
How Can I make it smoothly zooming?