找回密码
 加入
搜索
查看: 2627|回复: 3

[图形处理] GDI+如何画像Word中的标注图形?

[复制链接]
发表于 2017-1-24 20:12:20 | 显示全部楼层 |阅读模式
想自画如Word中的标注图形,然后在图形内添加上文字。
初学GDI+,储备知识太少,只会用区域画出图形轮廓,却又无法实现描边,请问应该如何画出如下的四种图形?

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
        Local $iW, $iH, $hGUI, $hGraphic, $hBrush, $hPen, $hPath, $hPath_Clone, $hMatrix, $hPath2

        ; 创建 GUI
        $iW = 600
        $iH = 600
        $hGUI = GUICreate("GDI+ UDF 示例", $iW, $iH)
        GUISetState(@SW_SHOW)

        _GDIPlus_Startup()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;在句柄指定的窗口创建图形对象
        _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;设置图形对象渲染质量(抗锯齿)
        _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)

        $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
        $hPen = _GDIPlus_PenCreate(0xFF000000, 2)

        $hPath = _GDIPlus_PathCreate() ;创建新路径对象
        _GDIPlus_PathAddRectangle($hPath, 100, 100, 200, 100)
        $hRegion1 = _GDIPlus_RegionCreateFromPath($hPath)
        ;$hRegion1 = _GDIPlus_RegionCreateFromRect(100, 100, 200, 100)
        $hPath2 = _GDIPlus_PathCreate()
        Local $aPoints[4][2] = [[3]]
        $aPoints[1][0] = 130
        $aPoints[1][1] = 190
        $aPoints[2][0] = 200
        $aPoints[2][1] = 190
        $aPoints[3][0] = 90
        $aPoints[3][1] = 230
        _GDIPlus_PathAddPolygon($hPath2, $aPoints)
        $hRegion2 = _GDIPlus_RegionCreateFromPath($hPath2)

        _GDIPlus_RegionCombineRegion($hRegion1, $hRegion2, 2)
        _GDIPlus_GraphicsFillRegion($hGraphic, $hRegion1, $hBrush)

        ;_GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush)
        ;_GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen)
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; 清理资源
        _GDIPlus_PathDispose($hPath2)
        _GDIPlus_PathDispose($hPath)
        _GDIPlus_RegionDispose($hRegion1)
    _GDIPlus_RegionDispose($hRegion2)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_PenDispose($hPen)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
EndFunc   ;==>Example

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2017-1-24 21:17:45 | 显示全部楼层
GDI   做界面很不错~学习
发表于 2017-2-4 11:37:38 | 显示全部楼层
本帖最后由 水木子 于 2017-2-4 11:41 编辑

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
        Local $hGUI, $hGraphic, $aPoints[13][2], $aPoints2[5][2]

        ; Create GUI
        $hGUI = GUICreate("GDI+", 400, 300)
        GUISetState(@SW_SHOW)

        ; Draw a polygon
        _GDIPlus_Startup()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        $hPen = _GDIPlus_PenCreate(0xffff0000, 2)

        $aPoints[0][0] = 12
        
        $aPoints[1][0] = 100
        $aPoints[1][1] = 100
        
        $aPoints[2][0] = 150
        $aPoints[2][1] = 150
        
        $aPoints[3][0] = 100
        $aPoints[3][1] = 200
        
        $aPoints[4][0] = 150
        $aPoints[4][1] = 200
        
        $aPoints[5][0] = 175
        $aPoints[5][1] = 175
        
        $aPoints[6][0] = 200
        $aPoints[6][1] = 200
        
        $aPoints[7][0] = 250
        $aPoints[7][1] = 200
        
        $aPoints[8][0] = 200
        $aPoints[8][1] = 150
        
        $aPoints[9][0] = 250
        $aPoints[9][1] = 100
        
        $aPoints[10][0] = 200
        $aPoints[10][1] = 100
        
        $aPoints[11][0] = 175
        $aPoints[11][1] = 125
        
        $aPoints[12][0] = 150
        $aPoints[12][1] = 100

        _GDIPlus_GraphicsDrawPolygon($hGraphic, $aPoints, $hPen)

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; Clean up resources
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
EndFunc   ;==>Example
 楼主| 发表于 2017-2-4 21:30:03 | 显示全部楼层
回复 3# 水木子

谢谢水木子大侠的关注,我查阅了许多,最后也只能通过画多边形或路径组合画出简单的三个来,但对小箭头的所指方向的不确定性,以其与矩形或椭圆的连结点坐标判断上力不从心,无法做到像Word中那样设置自如。目前,现在这个问题我只能再等一等了,等用到这儿再继续折腾吧!再次感谢,敬礼!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-24 00:44 , Processed in 0.083633 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表