[英]how to crop image with polygon in c#
我正在制作一个标签工具。
目标:通过在图片上绘制多边形,将多边形内部的图像导出到外部。
这是我在我的程序中画的。
但我不知道如何提取这个区域。 我想知道如何提取这个区域。 我已将上图的顶点保存在 object 中。 但我不知道如何通过这些顶点从图像中提取数据
=========================================
所以我找到了这个。 https://www.codeproject.com/Articles/703519/Cropping-Particular-Region-In-Image-Using-Csharp
但这行不通
出于同样的原因,它不起作用。 在帖子中,我打算使用opencvsharp 4.x,但是我现在正在修复的程序是.netframework 3.5,所以它不支持opencvsharp 4.x。 我应该怎么办?
==============================
我参考答案做了一个 function ,但它不起作用......我想知道为什么。
void CropImage(Bitmap bitmap, Point[] points)
{
Rectangle rect = CalculateMinBox(points, bitmap);
TextureBrush textureBrush = new TextureBrush(bitmap);
Bitmap bmp1 = new Bitmap(rect.Width, rect.Height);
Graphics g = Graphics.FromImage(bmp1);
g.FillPolygon(textureBrush, points);
Bitmap myBitmap = new Bitmap(rect.Width, rect.Height, g);
pictureBox1.Image = myBitmap;
string ima_path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
bmp1.Save(ima_path + "\\Image.png", ImageFormat.Png);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.