选择并剪切和替换图像区域

选择并剪切和替换图像区域

本文介绍了选择并剪切和替换图像区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我有一个图片框,并将图像导入到该图片框.我要选择此图片框(图像)的一个区域,例如"MS Paint中的自由格式选择" ,然后剪切选定的区域,并用另一个图像或系统颜色替换(填充)该区域.
您对这个问题有什么想法?!

Hi.
I have a picture box and import image to this picture box. I want select a region of this picture box (image) like "free-form selection in MS Paint" then cut selecteced region and replace (fill) this region with another image or a system color.
What is your idea for this problem?!
Thanks.

推荐答案

GraphicsPath myPath = new GraphicsPath();
...
myPath.AddLine(oldPoint, newPoint);
oldPoint = newPoint;
...



当您想影响实际图像时,请从路径创建一个Region并填充它:



When you want to affect the actual image, create a Region from the path and fill it:

Region myRegion = new Region(myPath);
using (Graphics g = Graphics.FromImage(myPicturePox.Image))
   {
   g.FillRegion(Brushes.Red, myRegion);
   }

您必须使图片框无效才能重新显示.
或者,您可以使用区域"仅引用用户标记为其他操作的图像部分.

You will have to Invalidate the picture box to re-display it.
Or you can use the Region to reference only those parts of the image the user has marked for other operations.


这篇关于选择并剪切和替换图像区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:06