C# 图片截取

it2022-05-09  23

#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

转载于:https://www.cnblogs.com/ybb521/p/3369738.html

相关资源:c#图片截取,缩放,等比缩放等功能

最新回复(0)