.Net 绘制可编辑图形

在图片上进行图形绘制,包括矩形框、圆、箭头、文字,可动态编辑绘制的内容,修改颜色和调整大小,此功能主要用于即时通讯程序截图编辑功能,支持导出图片文件。这里上传是源码,给有需要的人,避免重复劳动,大家可在此基础上进行深化开发,文章结尾有下载地址。

效果如下:

图1 基本绘制功能

图2 支持旋转和鼠标划过效果 

部分绘制代码:

/// 绘制一头大一头小的箭头
public class DOArrow : DrawableObject
    {
        public DOArrow()
        {
            Name = "DOArrow";
        }
        public override void Draw(Graphics g, bool isPreview = false)
        {
            if (isPreview || Selected)
            {
                base.DrawBorder(g);
            }

            // 计算矩形框对角线长度
            double len = Math.Sqrt(Math.Pow(Bounds.Width, 2) + Math.Pow(Bounds.Height, 2));

            AdjustableArrowCap lineCap = new AdjustableArrowCap(9, 9, true);
            lineCap.Filled = true;
            lineCap.MiddleInset = 3.1f;
            Pen pen = new Pen(Color, Size);
            pen.CustomStartCap = new AdjustableArrowCap(5, (int)len / 3 - 5, true);
            pen.CustomEndCap = lineCap;

            Point starPoint = Point.Empty; // 起点坐标
            Point endPoint = Point.Empty;  // 终点坐标

            switch (DrawDirection)
            {
                case DrawDirection.NWSE:
                    starPoint = new Point(Bounds.X, Bounds.Y);
                    endPoint = new Point(Bounds.Right, Bounds.Bottom);
                    break;

                case DrawDirection.NESW:
                    starPoint = new Point(Bounds.Right, Bounds.Y);
                    endPoint = new Point(Bounds.X, Bounds.Bottom);
                    break;

                case DrawDirection.SWNE:
                    starPoint = new Point(Bounds.X, Bounds.Bottom);
                    endPoint = new Point(Bounds.Right, Bounds.Y);
                    break;

                case DrawDirection.SENW:
                    starPoint = new Point(Bounds.Right, Bounds.Bottom);
                    endPoint = new Point(Bounds.X, Bounds.Y);
                    break;
            }

            g.DrawLine(pen, starPoint, endPoint);

            base.DrawControlPoints(g);
        }
    }

代码比较简单,基本都有注释,很容易看懂,源码下载地址为:

简单的图片可绘制编辑器-桌面系统文档类资源-CSDN下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值