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