question

HemanthB-9452 avatar image
0 Votes"
HemanthB-9452 asked Castorix31 edited

Pan & Zoom an image C#

Hi, I created an image viewer in C#. I want to know how I can add a zoom and pan feature to the picture box. I've searched the web for panning an image a lot but no use. I've searched zooming also. There are results for zooming like:

   Image Zoom(Image img, Size size)
         {
                
             Bitmap btm = new Bitmap(img, img.Width + (img.Width * size.Width / 100), img.Height + (img.Height * size.Height / 100));
             Graphics g = Graphics.FromImage(btm);
             g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
             return btm;
         }

But this code makes the zooming a lot slower, not sure why.
Please help

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered Castorix31 edited

I had posted a way in a recent thread : Image Function Rotate and zoom
or from XingyuZhao-MSFT in an older thread (VB, same code in c#) : Possible g.Transform usage


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That's actually a map viewing component right? I want it to zoom in the same picturebox with a trackbar smooth and efficiently.

0 Votes 0 ·

Another thread with a PictureBox and a Panel with MouseWheel : Image Zooming in VB.NET with previously drawn graphics
or with a Trackbar : A Zoomable and Scrollable PictureBox (not tested, just from Google...)


0 Votes 0 ·