I'm programming in c# (windows form) for image processing
purpose. I have a Bitmap
image. In my image I have closed curve which may be convex
or concave
. The boundary of curve is illustrated by a special color . I want to fill it by a filling color. I implement my method (some thing like flood fill) but I get stack over flow exception. How can write method some like this:
FillPoly(Bitmap bitmap, Color boundaryColor, Color fillingColor)
Note: I have AForge Net
and Emgu CV
libraries in my project. Any solution using these libraries will be accepted.
The method itself
// 1. Graphics is more general than Bitmap
// 2. You have to provide points of the desired polygon/curve
private static void FillPoly(Graphics graphics,
Color boundary,
Color fillingColor,
params Point[] points) {
if (null == graphics)
throw new ArgumentNullException("graphics");
using (SolidBrush brush = new SolidBrush(fillingColor)) {
using (Pen pen = new Pen(boundary)) {
//TODO: think over, do you want just a polygon
graphics.FillPolygon(brush, points);
graphics.DrawPolygon(pen, points);
//... or curve
// graphics.FillClosedCurve(brush, points);
// graphics.DrawClosedCurve(pen, points);
}
}
}
its using:
Bitmap bmp = new Bitmap(200, 200);
using (Graphics g = Graphics.FromImage(bmp)) {
FillPoly(g, Color.Blue, Color.Red,
new Point(5, 5),
new Point(105, 6),
new Point(85, 95),
new Point(125, 148),
new Point(8, 150));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.