如何在C#中放大和缩小图像? [英] How to zoom an image in&out in C#?

查看:856
本文介绍了如何在C#中放大和缩小图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对图像进行缩放.我不想调整 PictureBox ,但图像本身.

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

我该怎么做?

推荐答案

一种解决方案是:

  1. 创建所需尺寸的新图像(例如原始图像尺寸的200%或50%)
  2. 使用 Graphics.DrawImage(Image,Rectangle)将原始图像绘制为新图像. ,它将给定图像以给定大小绘制到给定位置的新图像上
  3. 将新图像设置为PictureBox
  4. 的源
  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);

这篇关于如何在C#中放大和缩小图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆