C# 圖片截取


#region 原圖大小

Bitmap sourceBitmap = new Bitmap(picBox.Width, picBox.Height);
panelImage.DrawToBitmap(sourceBitmap, new Rectangle(0, 0, picBox.Width, picBox.Height));

#endregion

#region 區域截取

Image imageSource = sourceBitmap;或者( Image.FromFile(filepath))
double orgWidth = IntDouble(imageSource.Width);
double orgHight = IntDouble(imageSource.Height);

Rectangle cropArea = new Rectangle();

double x = orgWidth / 2 - 145;(145是從中間開始向兩邊截圖的寬度,可以自定義)
double y = 0;

double width = 290;
double height = orgHight;

cropArea.X = DoubleInt(x);
cropArea.Y = DoubleInt(y);
cropArea.Width = DoubleInt(width);
cropArea.Height = DoubleInt(height);

Bitmap bmpImage = new Bitmap(imageSource);
Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);

 

newPicBox.Imae=bmpCrop;

#endregion


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM