【已解决】请教如何生成一张指定大小指定颜色的纯色图?
本帖最后由 zghwelcome 于 2018-9-29 17:37 编辑下面是我的代码,效率低而且边缘有噪点。求GDI大佬正确的写法该如何写?谢谢!
#include <colorConstants.au3>
#include <ScreenCapture.au3>
Local $iWidth = 550, $iHeight = 550, $iColor = $color_red
_GDIPlus_Startup()
Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iWidth)
Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp)
For $iY = 0 To $iHeight - 1
For $iX = 0 To $iWidth - 1
_GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, $iColor)
Next
Next
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\au3生成图片示例一个.jpg")
_WinAPI_DeleteObject($hHBmp)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
本帖最后由 zghwelcome 于 2018-9-29 17:36 编辑
下面的代码为什么只能黑色或白色背景呢?
#include <Constants.au3>
#include <GDIPlus.au3>
#include <WinAPIGdi.au3>
;============ 问题解决了
Local $iWidth = 550, $iHeight = 550, $iColor = Hex($color_red, 6)
$iColor = Hex('0xFF' & $iColor, 8) ;//原来的错误代码
$iColor = '0x' & Hex('0xFF' & $iColor, 8) ;//修正后的
_GDIPlus_Startup()
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hGraphics, $iColor)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\纯色图.jpg")
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_ImageDispose($hBitmap)
_GDIPlus_Shutdown()
是这样子
#include <ScreenCapture.au3>
Local $iWidth = 550, $iHeight = 550
Example()
Func Example()
Local $hGUI
; 创建 GUI
$hGUI = GUICreate("屏幕捕获", $iWidth, $iHeight, -1, -1)
GUISetBkColor(0x009900)
GUISetState(@SW_SHOW)
Sleep(250)
; 捕获窗口
_ScreenCapture_CaptureWnd(@ScriptDir & "\A1.jpg", $hGUI, 20, 40, $iWidth - 40, $iHeight - 45)
ShellExecute(@ScriptDir & "\A1.jpg")
EndFunc ;==>Example
页:
[1]