Nabend Leute,
ich nutze SetBitmap um ein PNG auf eine ChildGui zu setzen. Nun hab ich die Funktion _ZoomOut geschrieben, welches halt das Image verkleinert und transparent macht. Wenn es nun verkleinert wird, wird es ja nach links oben verkleinert natürlich. Was muss ich machen, damit es zur Mitte verkleinert wird?
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)
Global Const $AC_SRC_ALPHA = 1
[/autoit] [autoit][/autoit] [autoit]Global $hGui = GUICreate("Visu", 400, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUICtrlCreateButton("Zoom Out", 20, 20, 80, 25)
GUICtrlSetOnEvent(-1, "_ZoomOut")
GUISetState()
_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile("Rect.png")
$hImage = Scale_Image($hImage, _GDIPlus_ImageGetWidth($hImage), _GDIPlus_ImageGetHeight($hImage))
Global $hGuiChild = GUICreate("", _GDIPlus_ImageGetWidth($hImage), _GDIPlus_ImageGetHeight($hImage), 100, 100, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGui)
SetBitmap($hGuiChild, $hImage, 255)
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hImage)
GUISetState()
While 1
Sleep(100)
WEnd
Func _ZoomOut()
Local $_hImage = _GDIPlus_ImageLoadFromFile("Rect.png")
Local $_fScale = 1.0
Local $_aWGP = WinGetPos($hGuiChild)
For $i = 250 To 0 Step -10
$_fScale -= 0.02
$_hImageNew = Scale_Image($_hImage, _GDIPlus_ImageGetWidth($_hImage) * $_fScale, _GDIPlus_ImageGetHeight($_hImage) * $_fScale)
SetBitmap($hGuiChild, $_hImageNew, $i)
Sleep(20)
Next
_GDIPlus_ImageDispose($_hImage)
_WinAPI_DeleteObject($_hImage)
EndFunc
Func _Exit()
_GDIPlus_Shutdown()
Exit
EndFunc
Func Scale_Image($hImage, $newW, $newH)
Local $newImage = _GDIPlus_BitmapCreateFromScan0($newW, $newH)
Local $hContext = _GDIPlus_ImageGetGraphicsContext($newImage)
_GDIPlus_GraphicsSetInterpolationMode($hContext, 7)
_GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $newW, $newH)
_GDIPlus_GraphicsDispose($hContext)
Return SetError(0, 0, $newImage)
EndFunc
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[6]
EndFunc ;==>_GDIPlus_BitmapCreateFromScan0
Func _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphics, "int", $iInterpolationMode)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsSetInterpolationMode
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap