|
发表于 2014-9-27 17:30:56
|
显示全部楼层
本帖最后由 netegg 于 2014-9-27 17:50 编辑
[au3]#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
;#Include <GDIPlusEx.au3>
Global Const $STM_SETIMAGE = 0x0172
_GDIPlus_Startup()
$hBitmap = _GDIPlus_ScaleImage2(@ScriptDir & "\Torus.png", 50, 30)
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_GDIPlus_BitmapDispose($hBitmap)
$Form = GUICreate("Test", 600, 400)
Global $Pic = GUICtrlCreatePic("", 50, 40, 50, 30, -1, $WS_EX_CLIENTEDGE)
$hB = GUICtrlSendMsg($Pic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
If $hB Then _WinAPI_DeleteObject($hB)
GUISetState(@SW_SHOW,$Form)
;$cForm = GUICreate("Test", 100, 100,1,1,$WS_SizeBox)
; _WinAPI_SetParent($cForm,GUICtrlGetHandle($Pic))
;GUISetState(@SW_SHOW,$cForm)
;~ GUIRegisterMsg($WM_MOVE, "_WM_MOVE_SIZE")
;~ GUIRegisterMsg($WM_SIZE, "_WM_MOVE_SIZE")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_Shutdown()
Exit
EndSwitch
WEnd
Func _WM_MOVE_SIZE($hWnd, $Msg, $wParam, $lParam)
$hB = GUICtrlSendMsg($Pic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hB = ' & $hB & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
If $hB Then _WinAPI_DeleteObject($hB)
EndFunc
Func _GDIPlus_ScaleImage2($sFile, $iNewWidth, $iNewHeight, $iBGColor = 0xFFF0F0F0, $bBGClear = True, $iInterpolationMode = 7) ;coded by UEZ 2012
If Not FileExists($sFile) Then Return SetError(1, 0, 0)
Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
If @error Then Return SetError(2, 0, 0)
Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
;local $aArray[4] = _GDIPlus_ImageGetBounds($hImage)
Local $iW, $iH, $f, $fRatio
If $iWidth > $iHeight Then
$f = $iWidth / $iNewWidth
Else
$f = $iHeight / $iNewHeight
EndIf
$iW = Int($iWidth / $f)
$iH = Int($iHeight / $f)
If $iW > $iNewWidth Then
$fRatio = $iNewWidth / $iW
$iW = Int($iW * $fRatio)
$iH = Int($iH * $fRatio)
ElseIf $iH > $iNewHeight Then
$fRatio = $iNewHeight / $iH
$iW = Int($iW * $fRatio)
$iH = Int($iH * $fRatio)
EndIf
Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Then Return SetError(3, 0, 0)
$hBitmap = $hBitmap[6]
Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
If $bBGClear Then _GDIPlus_GraphicsClear($hBmpCtxt, $iBGColor)
DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode)
_GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iW, $iH)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hBmpCtxt)
Return $hBitmap
EndFunc[/au3] |
|