简单转了一下,更多参数自己照作添加
DrawImg.au3
#include <GDIPlus.au3>;内嵌GDI+的UDF,以供程序调用GDI+
Func DrawImg($BgImg,$PngImg)
Global $hGraphic,$hBgImage,$BMPCLSID
If Not FileExists($BgImg) Then $BgImg = @ScriptDir & "\BackGround.bmp"
If Not FileExists($PngImg) Then $PngImg = @ScriptDir & "\Form.png"
$BMPCLSID = '{557CF400-1A04-11D3-9A73-0000F81EF32E}';指定BMP的图像编码器,测试N次为个值是固定的,所以直接用,大家也可以用_GDIPlus_EncodersGetCLSID('BMP')
_GDIPlus_Startup();启动GDI+
$hBgImage = _GDIPlus_BitmapCreateFromFile($BgImg);从文件中创建一个位图对象
$hPngImage = _GDIPlus_ImageLoadFromFile($PngImg);创建基于文件的图像对象
$PngWidth = _GDIPlus_ImageGetWidth($hPngImage);返回图像对象的宽度
$PngHeight = _GDIPlus_ImageGetHeight($hPngImage);返回图像对象的高度
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBgImage);获取刚刚创建的位图对象的图形句柄
_GDIPlus_GraphicsSetSmoothingMode($hGraphic,2);设置图形的平滑度,使图形的图像有抗锯齿功能
DllCall($ghGDIPDll, "int", "GdipSetTextRenderingHint", "hwnd", $hGraphic , "int", 4);设置字体的平滑度,使图形的文字有抗锯齿功能
;~ _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPngImage, 1025, 10, $width, $height);在$hGraphic图形坐标30,0的位置绘制和$hPngImage高度和宽度一致的$hPngImage对象
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hPngImage, 1010, 10, 425, 350);在$hGraphic图形坐标1010,10的位置绘制和一个宽度为425,高度为300的$hPngImage对象
$SeatNum = "001"
$SerialNum = "SA12587300"
$Mac = "50-E5-49-D7-4A-15"
$Notices1 = "座位:" & $SeatNum
$Notices2 = "请勿带饮水零食到机位"
$Notices3 = "课后请将键盘鼠标归位"
$Notices4 = "出厂编号:" & $SerialNum
$Notices5 = "MAC地址:" & $Mac
_PenImg($Notices1, "0xffffffff", "微软雅黑", "50", "1", "2", "1090", "50", "0", "0")
_PenImg($Notices2, "0xffffffff", "微软雅黑", "25", "1", "2", "1085", "160", "0", "0")
_PenImg($Notices3, "0xffffffff", "微软雅黑", "25", "1", "2", "1085", "200", "0", "0")
_PenImg($Notices4, "0xffffffff", "微软雅黑", "20", "1", "2", "1100", "260", "0", "0")
_PenImg($Notices5, "0xffffffff", "微软雅黑", "18", "1", "2", "1070", "290", "0", "0")
#CS $String = "座位:001" & @CRLF & "";定义字符串
$Color = "0xffffffff";定义_GDIPlus_BrushCreateSolid实心画笔的颜色
$FontType = "微软雅黑";定义_GDIPlus_FontFamilyCreate字体
$FontSize = "50";定义_GDIPlus_FontCreate字体大小
$FontStyle = "1";定义_GDIPlus_FontCreate字体为粗体
$FontUnit = "2";定义_GDIPlus_FontCreate坐标参照为像素
$X = "1090";定义_GDIPlus_RectFCreate矩形左上角 X 坐标
$Y = "50";定义_GDIPlus_RectFCreate矩形左上角 Y 坐标
$Width = "0";定义_GDIPlus_RectFCreate矩形宽度
$Height = "0";定义_GDIPlus_RectFCreate矩形高度
#CE
_GDIPlus_ImageSaveToFileEx($hBgImage, @ScriptDir & "\Wallpaper.bmp",$BMPCLSID,0);把位图对象保存为BMP文件
_GDIPlus_GraphicsDispose($hGraphic);释放资源
_WinAPI_DeleteObject($hBgImage);释放资源
_GDIPlus_Shutdown();关闭GDI+
EndFunc
Func _PenImg($String, $Color, $FontType, $FontSize, $FontStyle, $FontUnit, $X, $Y, $Width, $Height) ;_PenImg使用画笔在图片上写字
$hBrush = _GDIPlus_BrushCreateSolid($Color);创建实心画笔对象,其中Alpha通道值为$Color
$hFormat = _GDIPlus_StringFormatCreate();创建字符串格式对象
$hFamily = _GDIPlus_FontFamilyCreate($FontType);创建字体为"微软雅黑"的字体族对象
$hFont = _GDIPlus_FontCreate($hFamily, $FontSize, $FontStyle,$FontUnit);用上面创建的字体族创建一个字体大小为50,粗体,坐标参照为像素的字体对象,坐标参照很重要,会影响到字体在图形上的位置
$tLayout = _GDIPlus_RectFCreate($X, $Y, $Width, $Height);创建 $tagGDIPRECTF 数据结构
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $String, $hFont, $tLayout, $hFormat);根据上面创建的字体、字符串等信息测量字符串在图形中的尺寸,以便在图形中绘制
_GDIPlus_GraphicsDrawStringEx($hGraphic, $String, $hFont, $aInfo[0], $hFormat, $hBrush);在图形中绘制上面创建的字符串对象
EndFunc
调用方法
#include <DrawImg.au3>
$BgImg = @ScriptDir & "\BackGround.bmp"
$PngImg = @ScriptDir & "\Form.png"
DrawImg($BgImg,$PngImg)
|