Jump to content
DemAY

I Cant Save the Diff Image with _GDIPlus_ImageSaveToFile

Recommended Posts

DemAY

 

Hello everybody, I try to save a diff between 2 BMP but that does not work. The display on the screen works. Can say with one what I'm doing wrong.

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WinAPIHObj.au3>

Global $hGUI = GUICreate("GDI+ ", 1920, 1109)

_GDIPlus_Startup()

$ist = @DesktopDir & "\Schaden_soll.bmp"
$soll = @DesktopDir & "\Schaden_ist.bmp"

_WinAPI_BitmapsGetDiff($soll, $ist, @DesktopDir & "\Diff_SRCAND.png", $SRCAND ) ; Ideale Anzeige !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ShellExecute(@DesktopDir & "\Diff_SRCAND.png")

_GDIPlus_Shutdown()


Func _WinAPI_BitmapsGetDiff($sFile1, $sFile2, $sSave, $iROP = $MERGEPAINT) ;coded by UEZ 2014-02-10
    Local Const $hBitmap1 = _GDIPlus_BitmapCreateFromFile($sFile1)
    If @error Then Return SetError(1, 0, 0)
    Local Const $hBitmap2 = _GDIPlus_BitmapCreateFromFile($sFile2)
    If @error Then
        _GDIPlus_BitmapDispose($hBitmap1)
        Return SetError(2, 0, 0)
    EndIf

    Local Const $iW = _GDIPlus_ImageGetWidth($hBitmap1), $iH = _GDIPlus_ImageGetHeight($hBitmap1)
    If _GDIPlus_ImageGetWidth($hBitmap2) <> $iW Or _GDIPlus_ImageGetHeight($hBitmap2) <> $iH Then
        _GDIPlus_BitmapDispose($hBitmap1)
        _GDIPlus_BitmapDispose($hBitmap2)
        Return SetError(3, 0, 0)
    EndIf
    Local Const $hHBitmap1 = _WinAPI_CreateDIB($iW, $iH)
    Local Const $hD1 = _WinAPI_GetWindowDC(0)
    Local Const $hDC_backbuffer1 = _WinAPI_CreateCompatibleDC($hD1)
    Local Const $DC_obj1 = _WinAPI_SelectObject($hDC_backbuffer1, $hHBitmap1)
    Local Const $hGraphic1 = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer1)
    _GDIPlus_GraphicsSetInterpolationMode($hGraphic1, 5)
    _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 0, 0, $iW, $iH)

    Local Const $hHBitmap2 = _WinAPI_CreateDIB($iW, $iH)
    Local Const $hD2 = _WinAPI_GetWindowDC(0)
    Local Const $hDC_backbuffer2 = _WinAPI_CreateCompatibleDC($hD2)
    Local Const $DC_obj2 = _WinAPI_SelectObject($hDC_backbuffer2, $hHBitmap2)
    Local Const $hGraphic2 = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer2)
    _GDIPlus_GraphicsSetInterpolationMode($hGraphic2, 5)
    _GDIPlus_GraphicsDrawImageRect($hGraphic2, $hBitmap2, 0, 0, $iW, $iH)

    Local Const $hHBitmap3 = _WinAPI_CreateDIB($iW, $iH)
    Local Const $hD3 = _WinAPI_GetWindowDC(0)
    Local Const $hDC_backbuffer3 = _WinAPI_CreateCompatibleDC($hD3)
    Local Const $DC_obj3 = _WinAPI_SelectObject($hDC_backbuffer3, $hHBitmap3)


    _WinAPI_BitBlt($hDC_backbuffer3, 0, 0, $iW, $iH, $hDC_backbuffer1, 0, 0, $SRCCOPY)
    _WinAPI_BitBlt($hDC_backbuffer3, 0, 0, $iW, $iH, $hDC_backbuffer2, 0, 0, $iROP)

    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_BitmapDispose($hBitmap2)

    $aFilename = StringSplit($sSave, "\")

    WinSetTitle($hGUI, "", $aFilename[$aFilename[0]])
    GUISetState(@SW_SHOW)


    $hBitmap3 = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap3)

     $hGraphicx = _GDIPlus_GraphicsCreateFromHWND($hGUI)
     $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap3)
    _GDIPlus_GraphicsDrawImage($hGraphicx, $hBitmap3, 0, 0)
    sleep(5000)

    _GDIPlus_ImageSaveToFile($hBitmap3, $sSave) ;----------------------> funzt net !!!!!!!!!!!!!!!!!!!!!!!!!!!

    _GDIPlus_BitmapDispose($hBitmap3)

    _GDIPlus_GraphicsDispose($hGraphic1)
    _WinAPI_SelectObject($hD1, $DC_obj1)
    _WinAPI_DeleteDC($hDC_backbuffer1)
    _WinAPI_DeleteObject($hHBitmap1)
    _WinAPI_ReleaseDC(0, $hD1)

    _GDIPlus_GraphicsDispose($hGraphic2)
    _WinAPI_SelectObject($hD2, $DC_obj2)
    _WinAPI_DeleteDC($hDC_backbuffer2)
    _WinAPI_DeleteObject($hHBitmap2)
    _WinAPI_ReleaseDC(0, $hD2)

    _WinAPI_SelectObject($hD3, $DC_obj3)
    _WinAPI_DeleteDC($hDC_backbuffer3)
    _WinAPI_DeleteObject($hHBitmap3)
    _WinAPI_ReleaseDC(0, $hD3)
    Return 1
EndFunc

 

Share this post


Link to post
Share on other sites
Melba23

DemAY,

You probably need the WinAPIConv file, but I suggest downloading all 3.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
DemAY

Melba23 Thx,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×