#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 446, 192, 124)
$Pic1 = GUICtrlCreatePic("", 48, 40, 380, 158)
_ImageResize("BKG-Body.jpg",380,158)
;~ _ImageResize("BKG-Body.jpg",380,158,1,4) ;修正偏差
GUICtrlCreatePic("BKG-Body.jpg", 48, 230, 380, 158)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _ImageResize($sInImage, $iW, $iH,$WFixed=0,$HFixed=0)
Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0,$hBitmap,$w_img,$h_img
$hWnd = _WinAPI_GetDesktopWindow()
$hDC = _WinAPI_GetDC($hWnd)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH)
_WinAPI_ReleaseDC($hWnd, $hDC)
;Start GDIPlus
_GDIPlus_Startup()
;Get the handle of blank bitmap you created above as an image
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP)
;Load the image you want to resize.
$hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)
$w_img = _GDIPlus_ImageGetWidth($hImage2)
$h_img = _GDIPlus_ImageGetHeight($hImage2)
ConsoleWrite($w_img &" "&$h_img)
;~ MsgBox(0,"",$hImage2)
;~ $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage2)
;Get the graphic context of the blank bitmap
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1)
;Draw the loaded image onto the blank bitmap at the size you want
;~ _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $ih)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage2,0,0,$w_img,$h_img,0,0,$iW+$WFixed, $iH+$HFixed)
_SetBitmapToCtrl($Pic1, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage1))
ConsoleWrite(_GDIPlus_ImageGetWidth($hImage1) &" "&_GDIPlus_ImageGetHeight($hImage1))
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_GraphicsDispose ($hGraphic)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
Return $hImage1
EndFunc
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
Local Const $STM_SETIMAGE = 0x0172
Local Const $IMAGE_BITMAP = 0
Local Const $SS_BITMAP = 0xE
Local Const $GWL_STYLE = -16
Local $hWnd = GUICtrlGetHandle($CtrlId)
If $hWnd = 0 Then Return SetError(1, 0, 0)
; set SS_BITMAP style to control
Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
If @error Then Return SetError(2, 0, 0)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
If @error Then Return SetError(3, 0, 0)
Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
If @error Then Return SetError(4, 0, 0)
If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
Return 1
EndFunc
素材: 请另存为