提取图像的自定义形状C# [英] extract a custom shape of image c#

查看:84
本文介绍了提取图像的自定义形状C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在从图像中提取对象,我可以检测到对象然后将其转换为点列表(对象的外部边界),但是问题是当我尝试按其点裁剪该对象时遇到很多问题

我需要提取按其拥有的点取整的对象.


这是我的代码

Hello all,

I am working on object extraction from image, I can detect the object then convert to list of points (outer boundaries of the object), but the problem is when I tried to crop this object by its points I got many problems

I need to extract the object rounded by its points which I have.


this is my code

//////////////////////////////////////////////////////////////////////
 // create a graphic path to hold the shape data
 System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
 // add a set of points that define the shape
 path.AddLines(pts);
  

 // close the shape
 path.CloseAllFigures();
 // create graphics object
 Graphics graph = pictureBox2.CreateGraphics();
 // set the clop region of the forms graphic object to be the new shape
 graph.Clip = new Region(path);
 // draw the image cliped to the custom shape
 graph.DrawImage(pictureBox1.Image, new Point(0, 0));
 //////////////////////////////////////////////////////////////////




被裁剪的区域在各个方向上都小于一个像素点中的对象


请帮忙!!!!!


做什么???????




the region which is cliped is less than the object in the points in one pixel in all directions


please help!!!!!


what to do?????

推荐答案

看看 ^ ]

您可以这样使用它:
Have a look at Graphics.SetClip[^]

You use it like this:
//////////////////////////////////////////////////////////////////////
// create a graphic path to hold the shape data
 System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
 // add a set of points that define the shape
 path.AddLines(pts);
  
 // close the shape
 path.CloseAllFigures();
 // create graphics object
 Graphics graph = pictureBox2.CreateGraphics();
 // set the clop region of the forms graphic object to be the new shape
 graph.SetClip(path, CombineMode.Replace);

 // draw the image cliped to the custom shape
 graph.DrawImage(pictureBox1.Image, new Point(0, 0));
 //////////////////////////////////////////////////////////////////



最好的问候
Espen Harlinn



Best regards
Espen Harlinn


感谢您的答复

但问题仍然存在,如果您在图像中有一条线且该线的高度为4像素,而该线的宽度为100像素,则该问题正好出现,执行此功能后,它将返回高度为3像素,宽度为99像素的线,

我认为问题恰好在于它填充了线条内部的图形路径,并且图形路径的边界没有填充,因此返回的图像将丢失这些像素


怎么办?
thank you for your reply

but the problem still, the problem exactly if you have a line in an image and the height of the line is 4 pixels and the width of the line is 100 pixel, after doing this function it return line with 3 pixels height and 99 pixels width,

I think the problem exactly on the graphicspath it fill what is inside the lines and the border of graphics path is not filled, so the returned image will lose these pixels


what to do??


这篇关于提取图像的自定义形状C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆