FloodFill() public method

Replaces the colors of a particular area:
public FloodFill ( int x, int y, Color newColor ) : Rectangle
x int start x
y int start y
newColor Color color to replace with
return System.Drawing.Rectangle
Exemplo n.º 1
0
 private void DoTool()
 {
     Rectangle rect;
     switch (Tool)
     {
         case ImageTool.Pen:
             DrawPenLine();
             break;
         case ImageTool.Line:
             _edit_canvas.DrawLine(_draw_pen, _start_anchor, _mouse);
             _end_anchor = _end_anchor = _mouse;
             break;
         case ImageTool.Rectangle:
             rect = Line.ToRectangle(new Line(_start_anchor, _mouse));
             if (!Outlined)
             {
                 rect.Width += 1;
                 rect.Height += 1;
                 _edit_canvas.FillRectangle(_draw_brush, rect);
             }
             else _edit_canvas.DrawRectangle(_draw_pen, rect);
             _end_anchor = _mouse;
             break;
         case ImageTool.Floodfill:
             FastBitmap bmap = new FastBitmap(_edit_layer);
             bmap.LockImage();
             rect = bmap.FloodFill(_mouse.X, _mouse.Y, DrawColor);
             bmap.UnlockImage();
             _start_anchor = rect.Location;
             _end_anchor.X = rect.Right;
             _end_anchor.Y = rect.Bottom;
             break;
     }
 }
Exemplo n.º 2
0
        private void DoTool(Graphics g)
        {
            g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
            int cx = x_off + cur_x, cy = y_off + cur_y;
            edit_region.Width++; edit_region.Height++;
            edit_region.X += x_off; edit_region.Y += y_off;
            g.SetClip(edit_region);
            switch (_tool)
            {
                case Tool.Pen:
                    g.DrawLine(SelPen, x_off + last_x, y_off + last_y, cx, cy);
                break;
                case Tool.Line:
                    g.DrawLine(SelPen, x_off + Origin.X, y_off + Origin.Y, cx, cy);
                break;
                case Tool.Rect:
                if (!Outline)
                {
                    using (SolidBrush brush = new SolidBrush(color))
                    {
                        g.FillRectangle(brush, edit_region);
                    }
                }
                else
                {
                    edit_region.Width--; edit_region.Height--;

                    if (edit_region.Width == 0 || edit_region.Height == 0)
                        g.DrawLine(SelPen, edit_region.X, edit_region.Y, edit_region.Right, edit_region.Bottom);
                    else
                        g.DrawRectangle(SelPen, edit_region);

                    edit_region.Width++; edit_region.Height++;
                }
                    break;
                case Tool.Fill:
                    FastBitmap bmap = new FastBitmap(edit_layer);
                    bmap.LockImage();
                    edit_region = bmap.FloodFill(cx, cy, color);
                    edit_region.Width++; edit_region.Height++;
                    bmap.UnlockImage();
                break;
                // case 4: ellipse
            }
            edit_region.Width--; edit_region.Height--;
            edit_region.X -= x_off; edit_region.Y -= y_off;
            g.ResetClip();
            g.Dispose();
        }