#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GDIPlus.au3>
Global $iWidth = 1300
Global $iHeight = 900
Global $h_cGUI_Width = 400
Global $h_cGUI_Height = 500
Global $h_cGUI_x = 400
Global $h_cGUI_y = 200
Global $image = _PathSplitByRegExp(@ScriptDir & '\test.bmp')
$hGUI = GUICreate('Example', $iWidth, $iHeight, 0, 0, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
_Pic(0)
_Pic(1)
_Pic(2)
_Pic(3)
_Pic(4)
GUISetState()
Func _Pic($n)
_GDIPlus_Startup()
$hSource = _GDIPlus_ImageLoadFromFile($image[0])
$Size = _GDIPlus_GetImageDimension($hSource)
Switch $n
Case 0
$hDestination = _GDIPlus_CreateBitmapFromScan0($iWidth, $iHeight, 0, _GDIPlus_GetImagePixelFormat($hSource))
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hDestination)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hSource, 0, 0, $iWidth, $iHeight)
_GDIPlus_ImageSaveToFile($hDestination, @ScriptDir & '\' & 'test' & $n & '.' & $image[4])
Case 1
$hDestination = _GDIPlus_CreateBitmapFromScan0($iWidth, $h_cGUI_y, 0, _GDIPlus_GetImagePixelFormat($hSource))
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hDestination)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hSource, 0, 0, $Size[0], $Size[1])
_GDIPlus_ImageSaveToFile($hDestination, @ScriptDir & '\' & 'test' & $n & '.' & $image[4])
GUICtrlCreatePic(@ScriptDir & '\' & 'test' & $n & '.' & $image[4], 0, 0, $iWidth, $h_cGUI_y)
Case 2
$hDestination = _GDIPlus_CreateBitmapFromScan0($iWidth, $iHeight - ($h_cGUI_Height + $h_cGUI_y), 0, _GDIPlus_GetImagePixelFormat($hSource))
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hDestination)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hSource, 0, -($h_cGUI_Height + $h_cGUI_y), $Size[0], $Size[1])
_GDIPlus_ImageSaveToFile($hDestination, @ScriptDir & '\' & 'test' & $n & '.' & $image[4])
GUICtrlCreatePic(@ScriptDir & '\' & 'test' & $n & '.' & $image[4], 0, $h_cGUI_Height + $h_cGUI_y, $iWidth, $iHeight - ($h_cGUI_Height + $h_cGUI_y))
Case 3
$hDestination = _GDIPlus_CreateBitmapFromScan0($h_cGUI_x, $iHeight, 0, _GDIPlus_GetImagePixelFormat($hSource))
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hDestination)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hSource, 0, 0, $Size[0], $Size[1])
_GDIPlus_ImageSaveToFile($hDestination, @ScriptDir & '\' & 'test' & $n & '.' & $image[4])
GUICtrlCreatePic(@ScriptDir & '\' & 'test' & $n & '.' & $image[4], 0, 0, $h_cGUI_x, $iHeight)
Case 4
$hDestination = _GDIPlus_CreateBitmapFromScan0(($iWidth - ($h_cGUI_x + $h_cGUI_Width)), $iHeight, 0, _GDIPlus_GetImagePixelFormat($hSource))
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hDestination)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hSource, -($h_cGUI_x + $h_cGUI_Width), 0, $Size[0], $Size[1])
_GDIPlus_ImageSaveToFile($hDestination, @ScriptDir & '\' & 'test' & $n & '.' & $image[4])
GUICtrlCreatePic(@ScriptDir & '\' & 'test' & $n & '.' & $image[4], ($h_cGUI_x + $h_cGUI_Width), 0, ($iWidth - ($h_cGUI_x + $h_cGUI_Width)), $iHeight)
EndSwitch
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_ImageDispose($hDestination)
_GDIPlus_ImageDispose($hSource)
_GDIPlus_Shutdown()
GuiCtrlSetState(-1, $GUI_DISABLE)
If $n = 0 Then $image[0] = @ScriptDir & '\test0.' & $image[4]
EndFunc ;==>_Pic
$h_cGUI = GUICreate('Child GUI', $h_cGUI_Width, $h_cGUI_Height, $h_cGUI_x, $h_cGUI_y, $WS_CHILD, BitOR($WS_EX_CLIENTEDGE, $WS_SIZEBOX), $hGUI)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _GDIPlus_CreateBitmapFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $Ret = DllCall($ghGDIPDll, 'uint', 'GdipCreateBitmapFromScan0', 'int', $iWidth, 'int', $iHeight, 'int', $iStride, 'int', $iPixelFormat, 'ptr', $pScan0, 'ptr*', 0)
If(@error) Or($Ret[0]) Then
Return SetError(1, 0, 0)
EndIf
Return $Ret[6]
EndFunc ;==>_GDIPlus_CreateBitmapFromScan0
Func _GDIPlus_GetImageDimension($hImage)
Local $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hImage, 'float*', 0, 'float*', 0)
If(@error) Or($Ret[0]) Then
Return SetError(1, 0, 0)
EndIf
Local $Result[2]
$Result[0] = $Ret[2]
$Result[1] = $Ret[3]
Return $Result
EndFunc ;==>_GDIPlus_GetImageDimension
Func _GDIPlus_GetImagePixelFormat($hImage)
Local $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImagePixelFormat', 'ptr', $hImage, 'uint*', 0)
If(@error) Or($Ret[0]) Then
Return SetError(1, 0, 0)
EndIf
Return $Ret[2]
EndFunc ;==>_GDIPlus_GetImagePixelFormat
Func _PathSplitByRegExp($sPath)
If StringStripWS($sPath, 8) = '' Then
Return SetError(1, 0, 0)
EndIf
$sPath = StringReplace($sPath, '/', '\')
Local $aRet = StringRegExp($sPath, '^(?i)([a-z]:|\\\\(?:\?\\)?[a-z0-9_.$]+\\[a-z0-9_.]+\$?)?(\\(?:[^\\/:*?"<>|\r\n]+\\)*)?([^\\/:*?"<>|\r\n.]*)\.?((?:[^.\\/:*?"<>|\r\n]+)?)$', 2)
Switch @error
Case 1
Return SetError(2, 0, 0) ;Array is invalid. No matches.
Case 2
Return SetError(3, @extended, 0) ;Bad pattern, array is invalid. @Extended = offset of error in pattern.
EndSwitch
Return $aRet
EndFunc ;==>_PathSplitByRegExp