20

我想为图像实现缩放。我不想调整PictureBox的大小,而是调整图像本身的大小。

我该怎么做呢?

4

2 回答 2

35

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);
于 2012-06-06T14:15:13.503 回答
1

我使用网络浏览器来实现这一点。

//loads the image
myWebBrowser.Navigate(@"C:\myimage.png");

从那里我使用 SendKeys 放大和缩小

myWebBrowser.Select(); //Selects browser.
SendKeys.Send("^{+}"); //Sends the control + key combo, causing the browser to zoom in. Replace the "+" with a "-" to zoom out.

这是一种有点奇怪的方法,但对我来说效果很好。我希望这个对你有用!

于 2019-06-20T20:08:57.750 回答