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();
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        public static Bitmap SetReplacesFloodFill(Bitmap bitmap, int x, int y, Color color)
        {
            var img = new FastBitmap(bitmap);

            img.LockImage();
            int width  = 0; //
            int height = 0; //
            var rect   = img.FloodFill(0, 0, color, width, height);

            img.ReplaceColor(Color.FromArgb(158, 148, 159), Color.White);

            img.Clone();
            img.UnlockImage();
            return(img.Image);
        }
Example #3
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;
            }
        }