关于DrawTools的分析- 一个优秀的C#开源绘图软件

国外大佬,曾经写过两个关于DrawTools相关的开源绘图软件。

我更新了一个优化的版本如下图,稍后会发布更新给大家。 需要的用户可发邮件给我 448283544@qq.com

应用于AGV地图编辑器如下:

那么这个优于很多普通的画布软件,包含点、多种线、矩形、椭圆基本图像,贝塞尔曲线。缩放,Redo,undo等等,那么也能自定义图像和自定义可以拖拽到画布的新的业务实体。

后面我将添加标尺和图像之间吸附, 功能将变得更加强大,与我们使用到的AutoCad类似!

应用于地图编辑器如下, 类似openTCS的C#实现:

Mark Miller

DrawTools 2014

Arnault Bonafos, 16 Jan 2014

Architecture

Dynamic handling for showing scroll bars

A dirty boolean is handled in GraphicsList, the canvas document, where it should be. To this Dirty property is associated a DocumentDirtyObserver interface.

Hide Copy Code

复制代码
public interface DocumentDirtyObserver
{
    void IsDirty(GraphicsList gList);
}

Every time the document is modified, look with the different draw tools, its Dirty property is set to true and any DocumentDirtyObserver is fired.

Hide Copy Code

复制代码
public bool Dirty
{
    get
    {
        return this.dirty;
    }
    set { this.dirty = value; if (this.dirty) { NotifyDirty(); } } } 

The class DrawArea implements the DocumentDirtyObserver, and every time the document is 'dirty', it calls AdjustRendering, which in turn computes the bounding box of the canvas document (GraphicsList).

Hide Copy Code

复制代码
void AdjustRendering()
{
    Size docSize;

    if (this.GraphicsList != null)
    {
        docSize = this.GraphicsList.GetSize();
        docSize.Width += 20; docSize.Height += 20; AutoScrollMinSize = docSize; } else { AutoScrollMinSize = new Size(0, 0); } Invalidate(); } 

This way, it implements the Mode/View/Controller design pattern, the GraphicsList being the model, DrawArea being the View and the draw Tools being the controller.

In the future, Dirty property should be handled in only one place (it is also handled in the DrawArea class).

Export the graph to JPEG format

The DrawTools 2014 architecture is good enough to be followed to implement a new menu strip option.

  1. Add a menu item to the menu bar

    Simply open the MainForm designer and add the option

  2. Link the MenuItem to a MainForm method to trigger the CommandExportToJpg

    Hide Copy Code

    复制代码
    private void CommandExportToJpg()
    {
        docManager.ExportToJpg();
    }
  3. Implement the user interface logic in the DocManager ExportToJpg

    I let you look at the DocManager.ExportToJpg

  4. Subscribe MainForm ExportEvent method implementation to DocManager event.

Hide Copy Code

复制代码
docManager.ExportEvent += docManager_ExportEvent;
  1. Implement MainForm logic to actually transform image bitmap into JPEG file.

    All is in the source code, I don't copy it here as it is essentially technical stuff.

相关推荐
执风挽^2 小时前
Python基础编程题2
开发语言·python·算法·visual studio code
Z9fish2 小时前
sse哈工大C语言编程练习20
c语言·开发语言·算法
萧鼎3 小时前
Python 包管理的“超音速”革命:全面上手 uv 工具链
开发语言·python·uv
Anastasiozzzz3 小时前
Java Lambda 揭秘:从匿名内部类到底层原理的深度解析
java·开发语言
缺点内向3 小时前
C#: 告别繁琐!轻松移除Word文档中的文本与图片水印
c#·自动化·word·.net
刘琦沛在进步3 小时前
【C / C++】引用和函数重载的介绍
c语言·开发语言·c++
机器视觉的发动机3 小时前
AI算力中心的能耗挑战与未来破局之路
开发语言·人工智能·自动化·视觉检测·机器视觉
HyperAI超神经4 小时前
在线教程|DeepSeek-OCR 2公式/表格解析同步改善,以低视觉token成本实现近4%的性能跃迁
开发语言·人工智能·深度学习·神经网络·机器学习·ocr·创业创新
R_.L4 小时前
【QT】常用控件(按钮类控件、显示类控件、输入类控件、多元素控件、容器类控件、布局管理器)
开发语言·qt
喵叔哟4 小时前
06-ASPNETCore-WebAPI开发
服务器·后端·c#