我来写一个,下面的代码合并图片是按垂直方式合并,如果LZ想水平合并需要修改一些代码,最后合并好的图像保存在桌面#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
_Main()
Func _Main()
Local $hBitmap1, $hBitmap2, $hBitmap3, $hImage1, $hImage2, $hImage3, $hGraphics, $Brush, $W
;初始化 GDI+ 库
_GDIPlus_Startup ()
;图像1
$Image1 = FileOpenDialog("选择图像1", @DesktopDir, "图像文件(*.jpg;*.bmp)")
If FileExists($Image1) = 0 Then Exit
$hImage1 = _GDIPlus_BitmapCreateFromFile($Image1) ;如果图像文件1存在,则载入并创建图像句柄
;图像2
$Image2 = FileOpenDialog("选择图像2", @DesktopDir, "图像文件(*.jpg;*.bmp)")
If FileExists($Image2) = 0 Then Exit
$hImage2 = _GDIPlus_BitmapCreateFromFile($Image2) ;如果图像文件2存在,则载入并创建图像句柄
If _GDIPlus_ImageGetWidth($hImage1) >= _GDIPlus_ImageGetWidth($hImage2) Then ;此处判断两个图像的大小,如果图像1的宽度>=图像2的宽度,则最后合成的图像以图像1的宽度为准,反之
$W = _GDIPlus_ImageGetWidth($hImage1)
Else
$W = _GDIPlus_ImageGetWidth($hImage2)
EndIf
;生成一个图像,用来存放合成后的图像,图像句柄的大小:以下以垂直合并为例:宽=两副图中最宽一副的宽度为准,高度=两副图高度相加
$hImage3 = _GDIPlus_BitmapCreateFromGraphics($W, _GDIPlus_ImageGetHeight($hImage1)+_GDIPlus_ImageGetHeight($hImage2), _GDIPlus_ImageGetGraphicsContext($hImage1))
$hGraphics = _GDIPlus_ImageGetGraphicsContext ($hImage3) ;取得图像句柄的图形对象句柄
;因为上一步生成的图像句柄背景色是黑色的,需要将背景色填充成白色
$Brush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ;创建一个实体画刷,画刷颜色定义为白色
_GDIPlus_GraphicsFillRect($hGraphics, 0, 0, $W, _GDIPlus_ImageGetHeight($hImage1)+_GDIPlus_ImageGetHeight($hImage2), $Brush) ;填充一个矩形,颜色为白色
;将图像1和图像2绘制到图像3中,此处是垂直合并的
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage1, 0, 0, _GDIPlus_ImageGetWidth($hImage1), _GDIPlus_ImageGetHeight($hImage1))
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage2, 0, _GDIPlus_ImageGetHeight($hImage1), _GDIPlus_ImageGetWidth($hImage2), _GDIPlus_ImageGetHeight($hImage2))
;保存垂直合并后的图像文件
_GDIPlus_ImageSaveToFile ($hImage3, @DesktopDir & "\Image1.jpg")
;释放资源
_GDIPlus_ImageDispose ($hImage1)
_GDIPlus_ImageDispose ($hImage2)
_GDIPlus_ImageDispose ($hImage3)
_GDIPlus_BrushDispose ($Brush)
_WinAPI_DeleteObject ($hBitmap1)
_WinAPI_DeleteObject ($hBitmap2)
;关闭GDI+库
_GDIPlus_ShutDown ()
EndFunc ;==>_Main
|