Sign in to follow this  
Followers 0
Lakes

GDIPlus_GraphicsFillPolygon

3 posts in this topic

This one is included in the GDIP include

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_GraphicsFillPolygon2
; Description ...: Uses a brush to fill the interior of a polygon
; Syntax.........: _GDIPlus_GraphicsFillPolygon2($hGraphics, $aPoints[, $hBrush = 0[, $iFillMode = 0]])
; Parameters ....: $hGraphics - Pointer to a Graphics object
;                 $aPoints   - Array that specify the vertices of the polygon:
;                 |[0][0] - Number of vertices
;                 |[1][0] - Point 1 X position
;                 |[1][1] - Point 1 Y position
;                 |[2][0] - Point 2 X position
;                 |[2][1] - Point 2 Y position
;                 |[n][0] - Point n X position
;                 |[n][1] - Point n Y position
;                 $hBrush   - Pointer to a Brush object that is used to paint the interior of the polygon. If 0, a black brush
;                 +will be used.
;                 $iFillMode - Fill mode of the interior of the polygon:
;                 |0 - The areas are filled according to the even-odd parity rule
;                 |1 - The areas are filled according to the nonzero winding rule
; Return values .: Success    - True
;                 Failure     - False and either:
;                 |@error and @extended are set if DllCall failed
;                 |$GDIP_STATUS contains a non zero value specifying the error code
; Remarks .......: None
; Related .......: _GDIPlus_GraphicsFillPolygon
; Link ..........; @@MsdnLink@@ GdipFillPolygon
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_GraphicsFillPolygon2($hGraphics, $aPoints, $hBrush = 0, $iFillMode = 0)
Local $iI, $iCount, $iTmpErr, $iTmpExt, $pPoints, $tPoints, $aResult
__GDIPlus_BrushDefCreate($hBrush)
$iCount = $aPoints[0][0]
$tPoints = DllStructCreate("float[" & $iCount * 2 & "]")
$pPoints = DllStructGetPtr($tPoints)
For $iI = 1 To $iCount
  DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
  DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
Next
$aResult = DllCall($ghGDIPDll, "uint", "GdipFillPolygon", "hwnd", $hGraphics, "hwnd", $hBrush, "ptr", $pPoints, "int", $iCount, "int", $iFillMode)
$iTmpErr = @error
$iTmpExt = @extended
__GDIPlus_BrushDefDispose()
If $iTmpErr Then Return SetError($iTmpErr, $iTmpExt, False)
$GDIP_STATUS = $aResult[0]
Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsFillPolygon2

But this one is not

; #FUNCTION# ===================================================================================
; Name...........: _GDIPlus_GraphicsFillPolygon
; Description ...: Fill a polygon
; Syntax.........: _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints[, $hBrush = 0])
; Parameters ....: $hGraphics - Handle to a Graphics object
; $aPoints - Array that specify the vertices of the polygon:
; |[0][0] - Number of vertices
; |[1][0] - Vertice 1 X position
; |[1][1] - Vertice 1 Y position
; |[2][0] - Vertice 2 X position
; |[2][1] - Vertice 2 Y position
; |[n][0] - Vertice n X position
; |[n][1] - Vertice n Y position
; $hBrush - Handle to a brush object that is used to fill the polygon.
; - If $hBrush is 0, a solid black brush is used.
; Return values .: Success - True
; Failure - False
; Author ........:
; Modified.......: smashly
; Remarks .......:
; Related .......:
; Link ..........; @@MsdnLink@@ GdipFillPolygonI
; Example .......; Yes
; ===============================================================================================
Func _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $hBrush = 0)
Local $iI, $iCount, $pPoints, $tPoints, $aResult, $tmpError, $tmpExError
$iCount = $aPoints[0][0]
$tPoints = DllStructCreate("int[" & $iCount * 2 & "]")
$pPoints = DllStructGetPtr($tPoints)
For $iI = 1 To $iCount
DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
Next
_GDIPlus_BrushDefCreate($hBrush)
$aResult = DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "hWnd", $hGraphics, "hWnd", $hBrush, _
"ptr", $pPoints, "int", $iCount, "int", "FillModeAlternate")
$tmpError = @error
$tmpExError = @extended
_GDIPlus_BrushDefDispose()
If $tmpError Then Return SetError($tmpError, $tmpExError, False)
Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc ;==>_GDIPlus_GraphicsFillPolygon

So I should be able to replace _GDIPlus_GraphicsFillPolygon with _GDIPlus_GraphicsFillPolygon2 and just add a zero at the end, but it crashes autoit.

Here`s the example I`m looking at, with the _GDIPlus_GraphicsFillPolygon2 commented out.

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstants.au3>
#include <GDIP.au3>
Global $width = 700
Global $height = 300
Global $iTrans
$hwnd = GUICreate("test", $width, $height)
GUISetState()
If Not FileExists(@DesktopDir & "\bitmap.png") Then InetGet("http://www.autoitscript.com/forum/uploads/monthly_10_2008/post-31256-1224504936_thumb.png", _
                                                                                @DesktopDir & "\bitmap.png")
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics, 0xFF008800)
$image = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\bitmap.png")
$iwidth = _GDIPlus_ImageGetWidth($image)
$iheight = _GDIPlus_ImageGetHeight($image)
$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
$brush = _GDIPlus_BrushCreateSolid(0xFF000000)
$family = _GDIPlus_FontFamilyCreate("Arial")
$font = _GDIPlus_FontCreate($family, 24)
$layout = _GDIPlus_RectFCreate(0, 250, $width, $height)
$format = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($format, 2)
_GDIPlus_GraphicsDrawStringEx($graphics, "Normal   ", $font, $layout, $format, $brush)
_GDIPlus_GraphicsDrawImageRect($graphics, $image, 480, 20, $iwidth, $iheight)
_GDIPlus_StringFormatSetAlign($format, 1)
_GDIPlus_GraphicsDrawStringEx($graphics, "Top and Bottom Fade ", $font, $layout, $format, $brush)
GDIPlus_TopBotFade($hGraphic, $image, $iheight / 2 - 20, 30, 0xFF666666, 0xFF333333)
_GDIPlus_GraphicsDrawImage($graphics, $hBMPBuff, 250, 20)
_GDIPlus_StringFormatSetAlign($format, 0)
_GDIPlus_GraphicsDrawStringEx($graphics, "  Bevelled", $font, $layout, $format, $brush)
;GDIPlus_AddBevel($graphics, $image, 30, 0xFF606060, 0xFFAFAFAF)
_GDIPlus_GraphicsDrawImage($graphics, $hBMPBuff, 20, 20)
Do
    sleep(10)
Until GUIGetMsg() = -3
_GDIPlus_ImageDispose($image)
_GDIPlus_BrushDispose($brush)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hBMPBuff)
_GDIPlus_FontDispose($font)
_GDIPlus_FontFamilyDispose($family)
_GDIPlus_StringFormatDispose($format)
_GDIPlus_Shutdown()
Func GDIPlus_TopBotFade($hGraphic, $image, $topless, $Botless, $TopColor, $iBotColor, $TotTrans = 1)
    Local $iwidth = _GDIPlus_ImageGetWidth($image)
    Local $iheight = _GDIPlus_ImageGetHeight($image)
    Local $aPoints[5][2] = [[4, 0],[0, 0],[$iwidth, 0],[$iwidth, $topless],[0, $topless]]
; _GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $TopColor,0)
    GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $TopColor)
    Local $aPoints[5][2] = [[4, 0],[0, $iheight - $Botless],[$iwidth, $iheight - $Botless],[$iwidth, $iheight],[0, $iheight]]
; _GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $iBotColor,0)
GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $iBotColor)
    For $n = 0 To $iheight - 1
        If ($iheight - $n) <= $Botless Then ; Bottom invisible up $topless
            $iTrans = (($iheight - $n) / $Botless)
        ElseIf $n <= $topless Then ; Top invisible down $topless
            $iTrans = $n / $topless
        Else
            $iTrans = $TotTrans
        EndIf
        If $iTrans > $TotTrans Then $iTrans = $TotTrans
        _GDIPlus_GraphicsDrawImageRectRectTrans($hGraphic, $image, 1, $n, $iwidth, 1, 1, $n, $iwidth, 1, 2, $iTrans)
    Next
    Return
EndFunc   ;==>GDIPlus_TopBotFade
Func GDIPlus_AddBevel($graphics, $image, $iBdr, $iTopLeftColor, $iBotRightColor)
    Local $iwidth = _GDIPlus_ImageGetWidth($image)
    Local $iheight = _GDIPlus_ImageGetHeight($image)
    Local $aPoints[4][2] = [[3, 0],[0, 0],[$iwidth, 0],[0, $iheight]]
; _GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $iTopLeftColor, 0)
     GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $iTopLeftColor)
    Local $aPoints[4][2] = [[3, 0],[$iwidth, 0],[$iwidth, $iheight],[0, $iheight]]
; _GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $iBotRightColor, 0)
     GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $iBotRightColor)
    For $n = 0 To $iBdr
        $iTrans = Round($n / $iBdr, 3)
        ;ConsoleWrite(" $iTrans  = " & $iTrans & "   $n = "& $n  & @CRLF)

_GDIPlus_GraphicsDrawImageRectRectTrans($hGraphic, $image, $n, $n, $iwidth - 2 * $n, $iheight - 2 * $n, $n, $n, $iwidth - 2 * $n, $iheight - 2 * $n, 2, $iTrans)
    Next
    Return
EndFunc   ;==>GDIPlus_AddBevel
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]")
    ;blending values:
    $x = DllStructSetData($tColorMatrix, 1, 1, 1) * DllStructSetData($tColorMatrix, 2, 1, 2) * DllStructSetData($tColorMatrix, 3, 1, 3) * _
            DllStructSetData($tColorMatrix, 4, $nTrans, 4) * DllStructSetData($tColorMatrix, 5, 1, 5)
    ;;create an image attributes object and update its color matrix
    $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)
_GDIPlus_ImageAttributesDispose($hImgAttrib)
Return
EndFunc   ;==>_GDIPlus_GraphicsDrawImageRectRectTrans
Func GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $iARGB = -1)
    Local $iI, $iCount, $pPoints, $tPoints, $aResult, $tmpError, $tmpExError
    $iCount = $aPoints[0][0]
    $tPoints = DllStructCreate("int[" & $iCount * 2 & "]")
    $pPoints = DllStructGetPtr($tPoints)
    For $iI = 1 To $iCount
        DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
        DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
    Next
    $hBrush = _GDIPlus_BrushCreateSolid($iARGB)
    $aResult = DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "hWnd", $hGraphics, "hWnd", $hBrush, _
            "ptr", $pPoints, "int", $iCount, "int", "FillModeAlternate")
    $tmpError = @error
    $tmpExError = @extended
    _GDIPlus_BrushDispose($hBrush)
    If $tmpError Then Return SetError($tmpError, $tmpExError, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>GDIPlus_GraphicsFillPolygon

2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites



The reason for the crash is that you call the function Func GDIPlus_TopBotFade($hGraphic, $image, $topless, $Botless, $TopColor, $iBotColor, $TotTrans = 1) with wrong parameter.

$TopColor is not a brush handle for the function.

Try this instead:

Func GDIPlus_TopBotFade($hGraphic, $image, $topless, $Botless, $TopColor, $iBotColor, $TotTrans = 1, $hBrush = 0)
    Local $iwidth = _GDIPlus_ImageGetWidth($image)
    Local $iheight = _GDIPlus_ImageGetHeight($image)
    Local $aPoints[5][2] = [[4, 0],[0, 0],[$iwidth, 0],[$iwidth, $topless],[0, $topless]]
    _GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $hBrush, 0)
;~     GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $TopColor)
    Local $aPoints[5][2] = [[4, 0],[0, $iheight - $Botless],[$iwidth, $iheight - $Botless],[$iwidth, $iheight],[0, $iheight]]
 _GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $hBrush, 0)
;~ GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $iBotColor)
    For $n = 0 To $iheight - 1
        If ($iheight - $n) <= $Botless Then ; Bottom invisible up $topless
            $iTrans = (($iheight - $n) / $Botless)
        ElseIf $n <= $topless Then ; Top invisible down $topless
            $iTrans = $n / $topless
        Else
            $iTrans = $TotTrans
        EndIf
        If $iTrans > $TotTrans Then $iTrans = $TotTrans
        _GDIPlus_GraphicsDrawImageRectRectTrans($hGraphic, $image, 1, $n, $iwidth, 1, 1, $n, $iwidth, 1, 2, $iTrans)
    Next
    Return
EndFunc   ;==>GDIPlus_TopBotFade

Br,

UEZ


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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks UEZ, donno how I missed that... :D

Solved.

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstants.au3>
#include <GDIP.au3>
Global $width = 700
Global $height = 300
Global $iTrans
$hwnd = GUICreate("test", $width, $height)
GUISetState()
If Not FileExists(@DesktopDir & "bitmap.png") Then InetGet("http://www.autoitscript.com/forum/uploads/monthly_10_2008/post-31256-1224504936_thumb.png", _
                                                                                @DesktopDir & "bitmap.png")
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics, 0xFF008800)
$image = _GDIPlus_ImageLoadFromFile(@DesktopDir & "bitmap.png")
$iwidth = _GDIPlus_ImageGetWidth($image)
$iheight = _GDIPlus_ImageGetHeight($image)
$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
$brush = _GDIPlus_BrushCreateSolid(0xFF000000)
$family = _GDIPlus_FontFamilyCreate("Arial")
$font = _GDIPlus_FontCreate($family, 24)
$layout = _GDIPlus_RectFCreate(0, 250, $width, $height)
$format = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($format, 2)
_GDIPlus_GraphicsDrawStringEx($graphics, "Normal   ", $font, $layout, $format, $brush)
_GDIPlus_GraphicsDrawImageRect($graphics, $image, 480, 20, $iwidth, $iheight)
_GDIPlus_StringFormatSetAlign($format, 1)
_GDIPlus_GraphicsDrawStringEx($graphics, "Top and Bottom Fade ", $font, $layout, $format, $brush)
GDIPlus_TopBotFade($hGraphic, $image, $iheight / 2 - 20, 30, 0xFF666666, 0xFF333333)
_GDIPlus_GraphicsDrawImage($graphics, $hBMPBuff, 250, 20)
_GDIPlus_StringFormatSetAlign($format, 0)
_GDIPlus_GraphicsDrawStringEx($graphics, "  Bevelled", $font, $layout, $format, $brush)
;GDIPlus_AddBevel($graphics, $image, 30, 0xFF606060, 0xFFAFAFAF)
_GDIPlus_GraphicsDrawImage($graphics, $hBMPBuff, 20, 20)
Do
    sleep(10)
Until GUIGetMsg() = -3
_GDIPlus_ImageDispose($image)
_GDIPlus_BrushDispose($brush)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hBMPBuff)
_GDIPlus_FontDispose($font)
_GDIPlus_FontFamilyDispose($family)
_GDIPlus_StringFormatDispose($format)
_GDIPlus_Shutdown()
Func GDIPlus_TopBotFade($hGraphic, $image, $topless, $Botless, $TopColor, $iBotColor, $TotTrans = 1, $hBrush = 0)
    Local $iwidth = _GDIPlus_ImageGetWidth($image)
    Local $iheight = _GDIPlus_ImageGetHeight($image)
    Local $aPoints[5][2] = [[4, 0],[0, 0],[$iwidth, 0],[$iwidth, $topless],[0, $topless]]
    _GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $hBrush, 0)
    Local $aPoints[5][2] = [[4, 0],[0, $iheight - $Botless],[$iwidth, $iheight - $Botless],[$iwidth, $iheight],[0, $iheight]]
_GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $hBrush, 0)
    For $n = 0 To $iheight - 1
        If ($iheight - $n) <= $Botless Then ; Bottom invisible up $topless
            $iTrans = (($iheight - $n) / $Botless)
        ElseIf $n <= $topless Then ; Top invisible down $topless
            $iTrans = $n / $topless
        Else
            $iTrans = $TotTrans
        EndIf
        If $iTrans > $TotTrans Then $iTrans = $TotTrans
        _GDIPlus_GraphicsDrawImageRectRectTrans($hGraphic, $image, 1, $n, $iwidth, 1, 1, $n, $iwidth, 1, 2, $iTrans)
    Next
    Return
EndFunc   ;==>GDIPlus_TopBotFade

Func GDIPlus_AddBevel($graphics, $image, $iBdr, $iTopLeftColor, $iBotRightColor, $hBrush = 0)
    Local $iwidth = _GDIPlus_ImageGetWidth($image)
    Local $iheight = _GDIPlus_ImageGetHeight($image)
    Local $aPoints[4][2] = [[3, 0],[0, 0],[$iwidth, 0],[0, $iheight]]
_GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $hBrush, 0)
    Local $aPoints[4][2] = [[3, 0],[$iwidth, 0],[$iwidth, $iheight],[0, $iheight]]
_GDIPlus_GraphicsFillPolygon2($hGraphic, $aPoints, $hBrush, 0)
    For $n = 0 To $iBdr
        $iTrans = Round($n / $iBdr, 3)
        ;ConsoleWrite(" $iTrans  = " & $iTrans & "   $n = "& $n  & @CRLF)
_GDIPlus_GraphicsDrawImageRectRectTrans($hGraphic, $image, $n, $n, $iwidth - 2 * $n, $iheight - 2 * $n, $n, $n, $iwidth - 2 * $n, $iheight - 2 * $n, 2, $iTrans)
    Next
    Return
EndFunc   ;==>GDIPlus_AddBevel

; #FUNCTION# ===================================================================================================
; Name...........: _GDIPlus_GraphicsDrawImageRectRectTrans
; Description ...: Draw an Image object with transparency
; Syntax.........: _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iSrcX, $iSrcY, [$iSrcWidth, _
;                                  [$iSrcHeight, [$iDstX, [$iDstY, [$iDstWidth, [$iDstHeight[, [$iUnit = 2]]]]]]])
; Parameters ....: $hGraphics   - Handle to a Graphics object
;                 $hImage     - Handle to an Image object
;                 $iSrcX       - The X coordinate of the upper left corner of the source image
;                 $iSrcY       - The Y coordinate of the upper left corner of the source image
;                 $iSrcWidth   - Width of the source image
;                 $iSrcHeight  - Height of the source image
;                 $iDstX       - The X coordinate of the upper left corner of the destination image
;                 $iDstY       - The Y coordinate of the upper left corner of the destination image
;                 $iDstWidth   - Width of the destination image
;                 $iDstHeight  - Height of the destination image
;                 $iUnit       - Specifies the unit of measure for the image
;                 $nTrans     - Value range from 0 (Zero for invisible) to 1.0 (fully opaque)
; Return values .: Success    - True
;                 Failure     - False
; Author ........: Siao
; Modified.......: Malkey
; Remarks .......:
; Related .......:
; Link ..........; http://www.autoitscript.com/forum/index....=&showtopic=70573&view=findpos
; Example .......; Yes
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 an image attributes object and update its color matrix 
Local  $iColorAdjustType = 1, $fEnable = 1
$hImgAttrib = _GDIPlus_ImageAttributesCreate()
; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_ColorMatrixCreateScale
; Description ...: Creates and initializes a scaling color matrix
; Syntax.........: _GDIPlus_ColorMatrixCreateScale($nRed, $nGreen, $nBlue[, $nAlpha = 1])
; Parameters ....: $nRed   - Red component scaling factor
;                 $nGreen - Green component scaling factor
;                 $nBlue  - Blue component scaling factor
;                 $nAlpha - Alpha component scaling factor
; Return values .: Success    - $tagGDIPCOLORMATRIX structure that contains a scaling color matrix
;                 Failure     - 0
; Remarks .......: A scaling color matrix is used to multiply components of a color by multiplier factors
;;create color matrix data
$tColorMatrix = _GDIPlus_ColorMatrixCreateScale(1, 1, 1, $nTrans)
$pColorMatrix = DllStructGetPtr($tColorMatrix) 
_GDIPlus_ImageAttributesSetColorMatrix($hImgAttrib, $iColorAdjustType, $fEnable, $pColorMatrix)

    ;draw image into graphic object with alpha blend
; #FUNCTION# ===================================================================================================
; Name...........: _GDIPlus_GraphicsDrawImageRectRectTrans
; Description ...: Draw an Image object with transparency
; Syntax.........: _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iSrcX, $iSrcY, [$iSrcWidth, _
;                                  [$iSrcHeight, [$iDstX, [$iDstY, [$iDstWidth, [$iDstHeight[, [$iUnit = 2]]]]]]])
; Parameters ....: $hGraphics   - Handle to a Graphics object
;                 $hImage     - Handle to an Image object
;                 $iSrcX       - The X coordinate of the upper left corner of the source image
;                 $iSrcY       - The Y coordinate of the upper left corner of the source image
;                 $iSrcWidth   - Width of the source image
;                 $iSrcHeight  - Height of the source image
;                 $iDstX       - The X coordinate of the upper left corner of the destination image
;                 $iDstY       - The Y coordinate of the upper left corner of the destination image
;                 $iDstWidth   - Width of the destination image
;                 $iDstHeight  - Height of the destination image
;                 $iUnit       - Specifies the unit of measure for the image
;                 $nTrans     - Value range from 0 (Zero for invisible) to 1.0 (fully opaque)
; Return values .: Success    - True
;                 Failure     - False
; Author ........: Siao
; Modified.......: Malkey
; Remarks .......:
; Related .......:
; Link ..........; http://www.autoitscript.com/forum/index....=&showtopic=70573&view=findpos
; Example .......; Yes
    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
_GDIPlus_ImageAttributesDispose($hImgAttrib)
Return
EndFunc   ;==>_GDIPlus_GraphicsDrawImageRectRectTrans

Link to original example for refernce is

Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

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
Sign in to follow this  
Followers 0