Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to zoom an image in&out in C#?

Tags:

I want to implement zoom for an image. I don't want to resize the PictureBox, but the image itself.

How do I do this?

like image 224
Mehmet Ince Avatar asked Jun 06 '12 14:06

Mehmet Ince


People also ask

How do I zoom in on a picture on my Iphone?

Adjust the magnification: Double-tap the screen with three fingers (without lifting your fingers after the second tap), then drag up or down. Or triple-tap with three fingers, then drag the Zoom Level slider. Move the Zoom lens: (Window Zoom) Drag the handle at the bottom of the Zoom lens.

What tool allows you to zoom in and out of pictures?

The Zoom Tool is used to zoom in and out of an image.


1 Answers

One solution is:

  1. Create new image of the desired size (for example 200% or 50% of original image size)
  2. Draw original image to new image using Graphics.DrawImage(Image, Rectangle);, which draws the given image to the new image at the given position with the given size
  3. Set new image as source for the PictureBox

Another way is to simple create a new bitmap instance like that:

Size newSize = new Size((int)(originalBitmap.Width * zoomFactor), (int)(originalBitmap.Height * zoomFactor));
Bitmap bmp = new Bitmap(originalBitmap, newSize);
like image 141
Thorsten Dittmar Avatar answered Sep 25 '22 02:09

Thorsten Dittmar