找回密码
 加入
搜索
查看: 1435|回复: 2

[AU3基础] GDI生成的矩形咋保存图片?

[复制链接]
发表于 2019-9-17 02:21:27 | 显示全部楼层 |阅读模式
#include <APIGdiConstants.au3>
#include <FontConstants.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WinAPIMisc.au3>
#include <WinAPIRes.au3>
#include <WinAPISys.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
; 创建 GUI
Local $hForm = GUICreate('测试 ' & StringReplace(@ScriptName, '.au3', '()'), 400, 400)
Local $idPic = GUICtrlCreatePic('', 0, 0, 400, 400)
Local $hPic = GUICtrlGetHandle($idPic)

; 创建位图
Local $hDev = _WinAPI_GetDC($hPic)
Local $hDC = _WinAPI_CreateCompatibleDC($hDev)
Local $hSource = _WinAPI_CreateCompatibleBitmapEx($hDev, 400, 400, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE)))
Local $hSv = _WinAPI_SelectObject($hDC, $hSource)

; 绘制对象
Local $hOldBrush = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DC_BRUSH))
Local $hOldPen = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DC_PEN))
_WinAPI_SetDCBrushColor($hDC, 0x33cc33)
_WinAPI_SetDCPenColor($hDC, 0x33cc33)



Local $hPattern = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\Pattern.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
; $hPattern = _WinAPI_LoadBitmap(_WinAPI_GetModuleHandle(@SystemDir & '\shell32.dll'), 138)
$hBrush = _WinAPI_CreateBrushIndirect($BS_PATTERN, 0, $hPattern)
$hObj = _WinAPI_SelectObject($hDC, $hBrush)
$tRECT = _WinAPI_CreateRect(0, 0, 240, 23)
;~ _WinAPI_OffsetRect($tRECT, 220, 279)
_WinAPI_RoundRect($hDC, $tRECT, 3, 3)

$tRECT = _WinAPI_CreateRect(0, 0, 240, 23)
_WinAPI_OffsetRect($tRECT, 0, 30)
_WinAPI_RoundRect($hDC, $tRECT, 3, 3)

_WinAPI_SelectObject($hDC, $hObj)
_WinAPI_DeleteObject($hPattern)
_WinAPI_DeleteObject($hBrush)




_WinAPI_SetTextColor($hDC, 0xffffff)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
Local $hFont = _WinAPI_CreateFont(20, 0, 0, 0, $FW_NORMAL, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $ANTIALIASED_QUALITY, $DEFAULT_PITCH, '微软雅黑')
$hObj = _WinAPI_SelectObject($hDC, $hFont)
_WinAPI_TextOut($hDC, 13, 1, '正常情况-----------------非常好')
_WinAPI_TextOut($hDC, 13, 31, '正常情况')
_WinAPI_SelectObject($hDC, $hObj)
_WinAPI_DeleteObject($hFont)

; 混合位图
Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDev, 400, 400)
$hBrush = _WinAPI_SelectObject($hDC, $hOldBrush)
_WinAPI_DeleteObject($hBrush)
Local $hPen = _WinAPI_SelectObject($hDC, $hOldPen)
_WinAPI_DeleteObject($hPen)
_WinAPI_SelectObject($hDC, $hBitmap)
_WinAPI_DrawBitmap($hDC, 0, 0, $hSource, $MERGECOPY)
_WinAPI_ReleaseDC($hPic, $hDev)
_WinAPI_SelectObject($hDC, $hSv)
_WinAPI_DeleteObject($hSource)
_WinAPI_DeleteDC($hDC)

; 将位图设置到控件
_SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
$hObj = _SendMessage($hPic, $STM_GETIMAGE)
If $hObj <> $hBitmap Then
    _WinAPI_DeleteObject($hBitmap)
EndIf
_GDIPlus_ImageSaveToFile($hSource, @ScriptDir & '\1.bmp')
GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = -3

_GDIPlus_ImageSaveToFile($hSource, @ScriptDir & '\1.bmp') 保存图片不成功


太复杂了,我就想画个简单的矩形,搞几个字保存图片
例子里面乱七八糟的一大堆,这是让人学不懂啊
 楼主| 发表于 2019-9-17 03:26:15 | 显示全部楼层
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

_GDIPlus_Startup()
Local Const $iWidth = 600, $iHeight = 600, $iBgColor = 0xFF303030
$hGui = GUICreate('', $iWidth, $iHeight)
GUISetState()



$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)

$hGraphics = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
$hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hGraphics)
_GDIPlus_GraphicsSetSmoothingMode($hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
$hPen = _GDIPlus_PenCreate(0xFFABCDEF, 4)
$bgBrush = _GDIPlus_BrushCreateSolid(0xFF303030)
$frBrush = _GDIPlus_BrushCreateSolid(0xFF33cc33)
_GDIPlus_GraphicsFillRect($hGfxCtxt, 0, 0, $iWidth, $iHeight, $bgBrush);绘制背景
 _GDIPlus_GraphicsFillRect($hGfxCtxt, 0, 0, 240, 20, $frBrush);绘制矩形

        $tBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
        $hFormat = _GDIPlus_StringFormatCreate()
        $hFamily = _GDIPlus_FontFamilyCreate("微软雅黑")
        $hFont = _GDIPlus_FontCreate($hFamily, 10, 0)
        $tLayout = _GDIPlus_RectFCreate(0, 0, 240, 20)
        _GDIPlus_GraphicsDrawStringEx($hGfxCtxt, "正常功能", $hFont, $tLayout, $hFormat, $tBrush)

 _GDIPlus_GraphicsFillRect($hGfxCtxt, 0, 30, 240, 20, $frBrush);绘制矩形
        $tLayout = _GDIPlus_RectFCreate(0, 30, 240, 20)
        _GDIPlus_GraphicsDrawStringEx($hGfxCtxt, "正常功能---------------啊", $hFont, $tLayout, $hFormat, $tBrush)

_GDIPlus_GraphicsDrawImage($hGraphic, $hGraphics, 0, 0)
_GDIPlus_ImageSaveToFile($hGraphics, @ScriptDir & '\1.bmp')

Do
Until GUIGetMsg() = -3

_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($bgBrush)
_GDIPlus_BrushDispose($frBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hGfxCtxt)
_GDIPlus_BitmapDispose($hGraphics)
_GDIPlus_Shutdown()

我知道了,有个GDI还有个GDI+
这个比GDI简单太多了,很容易就实现了,不过保存图片还是通过这个帖子
http://www.autoitx.com/forum.php ... amp;_dsign=b8e3ea6d
还不太理解,不过先暂时能用就OK了
发表于 2019-9-17 10:53:18 | 显示全部楼层
还不太理解,學習一下.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-25 07:29 , Processed in 0.069188 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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