Jump to content

GDIPlus Invert Color on Dimp Forms


Recommended Posts

I am trying to invert color on our Dimp forms but I am having trouble using _GDIPlus_BitmapCreateFromFile to select a .jpg from our archive folder. I'll provide the working script that's able to capture a section of the screen but _GDIPlus_BitmapCreateFromFile but when I try to replace capture with CreateFromFile and local $iW & $iH with ImageGetWidth & ImageGetHeight the script gets hung up.

;$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\328 Main Street.jpg") ; create a bitmap object from file
;$iW = _GDIPlus_ImageGetWidth($hBitmap)
;$iH = _GDIPlus_ImageGetHeight($hBitmap)

 

#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{Esc}", "_Exit")

Opt("GUIOnEventMode", 1);0=disabled, 1=OnEvent mode enabled

; replace with _GDIPlus_ImageGetWidth & _GDIPlus_ImageGetHeight
Local $iW = 400, $iH = 300

$hGui = GUICreate("Invert Colours Example", $iW, $iH)
GUISetOnEvent(-3, "_Exit")
GUISetState()

_GDIPlus_Startup()

;$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\328 Main Street.jpg") ; create a bitmap object from file

;$iW = _GDIPlus_ImageGetWidth($hBitmap)
;$iH = _GDIPlus_ImageGetHeight($hBitmap)
;ConsoleWrite("$iX  = " & $iX & "  $iY  = " & $iY & @CRLF)

$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
$hdc = _WinAPI_GetDC(0)
$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)

$sFileName = @DesktopDir & "\results.jpg"
_GDIPlus_ImageSaveToFile($bmp, $sFileName)
;ShellExecute(@DesktopDir & "\328 Main Street_New.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_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

 

Dimp.png.a1b6540ca1af56aa2c80f3259a594092.png

Link to comment
Share on other sites

#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{Esc}", "_Exit")

Opt("GUIOnEventMode", 1);0=disabled, 1=OnEvent mode enabled

_GDIPlus_Startup()

$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\328 Main Street.jpg") ; create a bitmap object from file
$hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

$iW = _GDIPlus_ImageGetWidth($hBitmap)
$iH = _GDIPlus_ImageGetHeight($hBitmap)
_GDIPlus_BitmapDispose($hBitmap)

$hGui = GUICreate("Invert Colours Example", $iW, $iH)
GUISetOnEvent(-3, "_Exit")
GUISetState()

$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
$hdc = _WinAPI_GetDC(0)
$hcdc = _WinAPI_CreateCompatibleDC($hdc)
$hcbmp = _WinAPI_CreateCompatibleBitmap($hdc, $iW, $iH)
_WinAPI_SelectObject($hcdc, $hcbmp)
$hcdc2 = _WinAPI_CreateCompatibleDC($hdc)
_WinAPI_SelectObject($hcdc2, $hBmp)

_WinAPI_BitBlt($hcdc, 0, 0, $iW, $iH, $hcdc2, 0, 0, $NOTSRCERASE)

$gc = _GDIPlus_GraphicsCreateFromHDC($hdc)
$bmp = _GDIPlus_BitmapCreateFromHBITMAP($hcbmp)
_GDIPlus_GraphicsDrawImage($hGraphic, $bmp, 0, 0)

$sFileName = @DesktopDir & "\results.jpg"
_GDIPlus_ImageSaveToFile($bmp, $sFileName)
;ShellExecute(@DesktopDir & "\328 Main Street_New.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_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hGraphicGUI)
    _WinAPI_DeleteObject($hBMPBuff)
    _WinAPI_ReleaseDC(0, $hdc)
    _WinAPI_DeleteDC($hcdc)
    _WinAPI_DeleteDC($hcdc2)
    _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

 

Link to comment
Share on other sites

@aa2zz6 you want to load the attached image (DIMP) and invert the colors?

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Try something like this here:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>


_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Dimp.png")
Global $aDim = _GDIPlus_ImageGetDimension($hImage)
Global $hImage_Negative = _GDIPlus_BitmapCreateNegative($hImage)
Global $hGUI = GUICreate("Test", $aDim[0], $aDim[1])
GUISetState()
Global $hCanvas = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage_Negative, 0, 0, $aDim[0], $aDim[1])

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_GraphicsDispose($hCanvas)
_GDIPlus_ImageDispose($hImage_Negative)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()


Func _GDIPlus_BitmapCreateNegative($hBitmap)
    Local $aDim = _GDIPlus_ImageGetDimension($hBitmap)
    Local $hBitmap_Neg = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1])
    Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap_Neg)
    Local $hIA = _GDIPlus_ImageAttributesCreate()
    Local $tNegMatrix = _GDIPlus_ColorMatrixCreateNegative()
    Local $pNegMatrix = DllStructGetPtr($tNegMatrix)
    _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pNegMatrix)
    _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hBitmap, 0, 0, $aDim[0], $aDim[1], 0, 0, $aDim[0], $aDim[1], $hIA)
    _GDIPlus_ImageAttributesDispose($hIA)
    _GDIPlus_GraphicsDispose($hGfx)
    Return $hBitmap_Neg
EndFunc   ;==>_GDIPlus_BitmapCreateNegative

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...