Function Reference


_GDIPlus_ImageAttributesSetColorKeys

Sets or clears the color key (transparency range) for a specified category

#include <GDIPlus.au3>
_GDIPlus_ImageAttributesSetColorKeys ( $hImageAttributes [, $iColorAdjustType = 0 [, $bEnable = False [, $iARGBLow = 0 [, $iARGBHigh = 0]]]] )

Parameters

$hImageAttributes Pointer to an ImageAttribute object
$iColorAdjustType [optional] The category for which the color key is set or cleared:
    0 - Color adjustment applies to all categories that do not have adjustment settings of their own
    1 - Color adjustment applies to bitmapped images
    2 - Color adjustment applies to brush operations in metafiles
    3 - Color adjustment applies to pen operations in metafiles
    4 - Color adjustment applies to text drawn in metafiles
$bEnable [optional] If True, transparency range for the specified category is applied; otherwise, transparency
$iARGBLow [optional] Alpha, Red, Green and Blue components of a color that specifies the low color-key value
$iARGBHigh [optional] Alpha, Red, Green and Blue components of a color that specifies the high color-key value

Return Value

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

Remarks

Any color that has each of its three components (red, green, blue) between the corresponding components of the high and low color keys is made transparent.

See Also

Search GdipSetImageAttributesColorKeys in MSDN Library.

Example

#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>

Example()

Func Example()
    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 600, $iHeight = 600

    Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    Local $hIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object

    _GDIPlus_ImageAttributesSetColorKeys($hIA, 0, True, 0x00000000, 0x00F7F7F7) ;make a range of colors transparent

    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

    _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $hIA) ;draw the bitmap while applying the color adjustment

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup GDI+ resources
    _GDIPlus_ImageAttributesDispose($hIA)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example