[英]Resize a PictureBox
我想在“圖片框”中顯示“調整大小的圖片”。 原始圖片是: 圖片以我的形式:
我的圖片框大小為500x500px。 我用於調整大小的方法:
public static Image ResizePicByWidth(Image sourceImage, double newWidth)
{
double sizeFactor = newWidth / sourceImage.Width;
double newHeigth = sizeFactor * sourceImage.Height;
Bitmap newImage = new Bitmap((int)newWidth, (int)newHeigth);
using (Graphics g = Graphics.FromImage(newImage))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(sourceImage, new Rectangle(0, 0, (int)newWidth, (int)newHeigth));
}
return newImage;
}
我用原始圖片和圖片框的寬度調用該方法。 但是如何正確調整圖片大小? 我希望我的表格顯示整個圖片。
PictureBox具有SizeMode屬性。 如果將其設置為“縮放”,它將自動調整其中圖像的大小以適合其中的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.