关于c# bitmap图像截取问题
发布网友
发布时间:2023-04-15 12:30
我来回答
共1个回答
热心网友
时间:2023-04-26 23:16
string path = @"C:\Users\huaping\Desktop\test.jpg";
Bitmap img = (Bitmap)Image.FromFile(path);
Bitmap newImg = new Bitmap(150,150);
Graphics g = Graphics.FromImage(newImg);
// 结果 x起点 y起点 要绘制的原图的部分的矩形 所用单位
g.DrawImage(img, 0, 0, new Rectangle(150, 150, newImg.Width, newImg.Height), GraphicsUnit.Pixel);
string savePath = @"C:\Users\huaping\Desktop\new.jpg";
newImg.Save(savePath);
g.Dispose();
newImg.Dispose();
img.Dispose();