Jump to content

Save inverted color ScreenCapture


Totter
 Share

Go to solution Solved by FireFox,

Recommended Posts

Hi

I have problem with creating image with inverted colors.

I can capture image and draw inverted color picture, but I cannot create inverted color image to use 

_GDIPlus_ImageSaveToFile ( $hImage, $picture_path )

to save it directly.

I'm using UEZ code that i do not fully understand. I thing that functions

_GDIPlus_GraphicsDrawImageRectRectIA

and 

_GDIPlus_GraphicsDrawImageRectRect

do part of the thing (draw inverted color picture).

The question is how to create inverted color image instead of drawing it to screen?

Func _Negative()    Local $tNegMatrix, $pNegMatrix
    If $hImage Then
        $hBackImage = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY)
        $hImageContext = _GDIPlus_ImageGetGraphicsContext($hBackImage)
        $tNegMatrix = _GDIPlus_ColorMatrixCreateNegative()
        $pNegMatrix = DllStructGetPtr($tNegMatrix)
        $hIA = _GDIPlus_ImageAttributesCreate()
        _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pNegMatrix)
        _GDIPlus_GraphicsDrawImageRectRectIA($hImageContext, $hImage, 0, 0, $iX, $iY, 0, 0, $iX, $iY, $hIA)
        _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBackImage, 0, 0, $iX, $iY, 0, 0, $iX, $iY)
        $tNegMatrix = 0
    EndIf
EndFunc




Func _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight, $hImageAttributes = 0, $iUnit = 2)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectRect", "hwnd", $hGraphics, "hwnd", $hImage, "float", $nDstX, "float", _
            $nDstY, "float", $nDstWidth, "float", $nDstHeight, "float", $nSrcX, "float", $nSrcY, "float", $nSrcWidth, "float", _
            $nSrcHeight, "int", $iUnit, "hwnd", $hImageAttributes, "int", 0, "int", 0)


    If @error Then Return SetError(@error, @extended, False)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsDrawImageRectRectIA
Link to comment
Share on other sites

  • Solution

Hi,
Instead of using the graphics from a GUI, use the graphics from the image you want to invert the color.
So the inverted color will be drawn on the image.

#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
 
Example()
 
Func Example()
    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 600, $iHeight = 600
 
    Local $hIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object
 
    Local $tColorMatrix = _GDIPlus_ColorMatrixCreateNegative() ;create negative color matrix
 
    _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $tColorMatrix) ;set negative color matrix
 
    Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iHeight) ;create a GDI bitmap by capturing an area on desktop
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap
    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
 
    Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
 
    _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $hIA) ;draw the bitmap while applying the color adjustment
 
    _GDIPlus_ImageSaveToFile($hBitmap, "test.jpg")
 
    ;cleanup GDI+ resources
    _GDIPlus_ImageAttributesDispose($hIA)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example
Br, FireFox.
Link to comment
Share on other sites

I have two more question.

I changed: 

_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $hIA)

to:

__GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, $iX1, $iY1, $iX2-$iX1, $iY2-$iY1,$iX1, $iY1,$iX2-$iX1, $iY2-$iY1, $hIA)

and code fails to invert colors

Note: $iX1, $iY1, $iX2, $iY2 are coordinates used to ScreenCapture

This works:

_

GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iX2-$iX1, $iY2-$iY1,0, 0,$iX2-$iX1, $iY2-$iY1, $hIA)

Question is why ?

$nSrcX The X coordinate of the upper left corner of the source image, 

$nSrcY The Y coordinate of the upper left corner of the source image,

$nDstX The X coordinate of the upper left corner of the destination image

and

$nDstY The Y coordinate of the upper left corner of the destination image

should be zero.

I did not wound explanation in HELP (checked all functions from GDIPlus in my code.)

Second question is why function _GDIPlus_ImageSaveToFile returns zero (@error = 0)

but do not fail to save image.

Should return 1.

In Help is written: 

Return Value Success: True.

Failure: False and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*).

Edited by Totter
Link to comment
Share on other sites

__GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, $iX1, $iY1, $iX2-$iX1, $iY2-$iY1,$iX1, $iY1,,$iX2-$iX1, $iY2-$iY1, $hIA)

Please use autoit code tags to post your code, and I can see a syntax error after the $iY1.

Second question is why function _GDIPlus_ImageSaveToFile returns zero (@error = 0)

but do not fail to save image.

Should return 1.

 

In Help is written: 

Return Value Success: True.

Failure: False and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*).

@error = 0 is not an error, it's a success. So the function returns 1.

Br, FireFox.

Link to comment
Share on other sites

add. 1

Sorry my mistake when pasting to forum (now repaired in original post).

This function does not fail but also does not invert colors. (Returns Succes)

__GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, $iX1, $iY1, $iX2-$iX1, $iY2-$iY1,$iX1, $iY1,$iX2-$iX1, $iY2-$iY1, $hIA)

works only in my code when written:

GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iX2-$iX1, $iY2-$iY1,0, 0,$iX2-$iX1, $iY2-$iY1, $hIA)

add.2

_GDIPlus_ImageSaveToFile($hBitmap,"testa1.jpg") 

saves testa1.jpg but returns 0 and error=0

 

Attaching program file as a proof:))

snapshot.au3

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...