Code : Tout sélectionner
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
; http://www.autoitscript.com/forum/index....=&showtopic=77799&view=findpos
; http://www.autoitscript.com/forum/index....=&showtopic=86951&view=findpos
Opt("GUIOnEventMode", 1);0=disabled, 1=OnEvent mode enabled
Local $Path = FileOpenDialog("Choose Image File", @ScriptDir & "","Images (*.gif;*.png;*.jpg;*.bmp)| All (*.*)")
If $Path <> "" Then
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile($Path)
Else
Exit
EndIf
Local $iW, $iH
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$hGui = GUICreate("B & W Negative Example", $iW, $iH)
GUISetOnEvent(-3, "_Exit")
GUISetState()
$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
;$hImage = _GDIPlus_ImageLoadFromFile ($FileLoad )
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
GUIRegisterMsg(0xF, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)
GUIRegisterMsg(0x85, "MY_PAINT"); $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize.
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
Sleep(1000)
_GDIPlus_GraphicsDrawImageRectRectTrans($hGraphic, $hBMPBuff, 0, 0)
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
Sleep(1000)
$hdc = _WinAPI_GetDC($hGui)
$hcdc = _WinAPI_CreateCompatibleDC($hdc)
$hcbmp = _WinAPI_CreateCompatibleBitmap($hdc, $iW, $iH)
_WinAPI_SelectObject($hcdc, $hcbmp)
_WinAPI_BitBlt($hcdc, 0, 0, $iW, $iH, $hdc, 0, 0, $NOTSRCERASE)
$gc = _GDIPlus_GraphicsCreateFromHDC($hdc)
$bmp = _GDIPlus_BitmapCreateFromHBITMAP($hcbmp)
_GDIPlus_GraphicsDrawImage($hGraphic, $bmp, 0, 0)
_gdiplus_imagesavetofile($hBMPBuff,"test2.bmp")
;$sFileName = @DesktopDir & "\GDIPlus_Image1.jpg"
;_GDIPlus_ImageSaveToFile($hBMPBuff, $sFileName)
;ShellExecute(@DesktopDir & "\GDIPlus_Image1.jpg")
_GDIPlus_GraphicsDispose($gc)
_GDIPlus_ImageDispose($bmp)
_WinAPI_DeleteObject($hcbmp)
GUIRegisterMsg(0xF, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)
GUIRegisterMsg(0x85, "MY_PAINT"); $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize.
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
While 1
Sleep(100)
WEnd
Func _Exit()
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hGraphicGUI)
_WinAPI_DeleteObject($hBMPBuff)
_WinAPI_ReleaseDC(0, $hdc)
_WinAPI_DeleteDC($hcdc)
_WinAPI_RedrawWindow(0, 0, 0, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_ALLCHILDREN))
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_Exit
Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
; Check, if the GUI with the Graphic should be repainted
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
_WinAPI_RedrawWindow($hGui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)); , $RDW_ALLCHILDREN
Return $GUI_RUNDEFMSG
EndFunc ;==>MY_PAINT
Func _GDIPlus_GraphicsDrawImageRectRectTrans($hGraphics, $hImage, $iSrcX, $iSrcY, $iSrcWidth = "", $iSrcHeight = "", $iDstX = "", $iDstY = "", $iDstWidth = "", $iDstHeight = "", $iUnit = 2, $nTrans = 1)
Local $tColorMatrix, $x, $hImgAttrib, $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage)
If $iSrcWidth = 0 Or $iSrcWidth = "" Then $iSrcWidth = $iW
If $iSrcHeight = 0 Or $iSrcHeight = "" Then $iSrcHeight = $iH
If $iDstX = "" Then $iDstX = $iSrcX
If $iDstY = "" Then $iDstY = $iSrcY
If $iDstWidth = "" Then $iDstWidth = $iSrcWidth
If $iDstHeight = "" Then $iDstHeight = $iSrcHeight
If $iUnit = "" Then $iUnit = 2
;;create color matrix data
$tColorMatrix = DllStructCreate("float[5];float[5];float[5];float[5];float[5]")
; Grey shading
$x = DllStructSetData($tColorMatrix, 1, 1, 1) * DllStructSetData($tColorMatrix, 1, 1, 2) * DllStructSetData($tColorMatrix, 1, 1, 3) * DllStructSetData($tColorMatrix, 4, $nTrans, 4) * DllStructSetData($tColorMatrix, 5, 0.1, 1) * DllStructSetData($tColorMatrix, 5, 0.1, 2) * DllStructSetData($tColorMatrix, 5, 0.1, 3) * DllStructSetData($tColorMatrix, 5, 1, 5)
$hImgAttrib = DllCall($ghGDIPDll, "int", "GdipCreateImageAttributes", "ptr*", 0)
$hImgAttrib = $hImgAttrib[1]
DllCall($ghGDIPDll, "int", "GdipSetImageAttributesColorMatrix", "ptr", $hImgAttrib, "int", 1,"int", 1, "ptr", DllStructGetPtr($tColorMatrix), "ptr", 0, "int", 0)
;;draw image into graphic object with alpha blend
DllCall($ghGDIPDll, "int", "GdipDrawImageRectRectI", "hwnd", $hGraphics, "hwnd", $hImage, "int", $iDstX, "int", $iDstY, "int", $iDstWidth, "int", $iDstHeight, "int", $iSrcX, "int", $iSrcY, "int", $iSrcWidth, "int", $iSrcHeight, "int", $iUnit, "ptr", $hImgAttrib, "int", 0, "int", 0)
;;clean up
DllCall($ghGDIPDll, "int", "GdipDisposeImageAttributes", "ptr", $hImgAttrib)
Return
EndFunc ;==>_GDIPlus_GraphicsDrawImageRectRectTrans