C#中pictureBox中从中间开始截取图片
在pictureBox的中间点上,(this.pictureBox1.width/2,0)开始,向两边截取指定宽度的图片,大侠们帮个忙指点指点。...
在pictureBox的中间点上,(this.pictureBox1.width/2,0)开始,向两边截取指定宽度的图片,大侠们帮个忙指点指点。
展开
展开全部
看要求是从中轴线向两边截取指定宽度图片了
//截图图片
private Image cropImage(int imgWidth)
{
// READ IMAG
Image imgSource= Image.FromFile(filepath);
//取原图片宽,高
double orgWidth = Int2Double(imgSource.Width);
double orgHeight = Int2Double(imgSource.Height);
//声明图片区域
Rectangle cropArea = new Rectangle();
//设定左上角点坐标
double x = orgWidth / 2 - imgWidth;
double y = 0;
//计算截取区域宽,高
double width = imgWidth*2;
double height = orgHeight;
//设定图片区域参数
cropArea.X = Double2Int(x);
cropArea.Y = Double2Int(y);
cropArea.Width = Double2Int(width);
cropArea.Height = Double2Int(height);
//截取图片
Bitmap bmpImage = new Bitmap(imgSource);
Bitmap bmpCrop = bmpImage.Clone(cropArea,
bmpImage.PixelFormat);
return bmpCrop;
}
private double Int2Double(int i)
{
return double.Parse(i.ToString());
}
private int Double2Int(double d)
{
return int.Parse(Math.Round(d, 0).ToString());
}
//截图图片
private Image cropImage(int imgWidth)
{
// READ IMAG
Image imgSource= Image.FromFile(filepath);
//取原图片宽,高
double orgWidth = Int2Double(imgSource.Width);
double orgHeight = Int2Double(imgSource.Height);
//声明图片区域
Rectangle cropArea = new Rectangle();
//设定左上角点坐标
double x = orgWidth / 2 - imgWidth;
double y = 0;
//计算截取区域宽,高
double width = imgWidth*2;
double height = orgHeight;
//设定图片区域参数
cropArea.X = Double2Int(x);
cropArea.Y = Double2Int(y);
cropArea.Width = Double2Int(width);
cropArea.Height = Double2Int(height);
//截取图片
Bitmap bmpImage = new Bitmap(imgSource);
Bitmap bmpCrop = bmpImage.Clone(cropArea,
bmpImage.PixelFormat);
return bmpCrop;
}
private double Int2Double(int i)
{
return double.Parse(i.ToString());
}
private int Double2Int(double d)
{
return int.Parse(Math.Round(d, 0).ToString());
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询