Jump to content

How to alternate between different transparent png images in gdi+ without flickering?


Recommended Posts

Hello

I am trying to alternate between two different transparent png images but it is not working none of them are removed instead they are both displayed at once.

I am very thankfull for all the help i can get on how to solve this problem.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <winapi.au3>
#include <gdiplus.au3>
local $Ipath = @scriptdir & "\splash-transparent.png"
local $Ipath2 = @scriptdir & "\splash-transparent-offline.png"
;local $Ipath = "c:\logout.png"
consolewrite('"' & @scriptdir & "\splash-transparent.png" & '"')
local $transColor = 0xABCDEF
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($Ipath)
$hImage2 = _GDIPlus_ImageLoadFromFile($Ipath2)
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$hGui = GUICreate("Test hover", $width, $height,1,1,$WS_POPUP,$WS_EX_LAYERED)
WinSetOnTop("Test hover", "", 1)

Guisetbkcolor($transColor,$hGui)
_WinAPI_SetLayeredWindowAttributes($hGui,$transColor,255)
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
_GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage,0,0,$width,$height)
Do
;WinSetOnTop("Test hover", "", 0)
WinSetOnTop("Test hover", "", 1)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
_GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage,0,0,$width,$height)
;_GDIPlus_ImageDispose($hImage)
sleep(1000)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphic)

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage2,0,0,$width,$height)
sleep(1000)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
Until GUIGetMsg() = -3
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Edited by fusion400
Link to comment
Share on other sites

Ok i have now updated the code with erasing but now it does not even show the second picture?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <winapi.au3>
#include <gdiplus.au3>
local $Ipath = @scriptdir & "\splash-transparent.png"
local $Ipath2 = @scriptdir & "\splash-transparent-offline.png"
;local $Ipath = "c:\logout.png"
consolewrite('"' & @scriptdir & "\splash-transparent.png" & '"')
local $transColor = 0xABCDEF
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($Ipath)
$hImage2 = _GDIPlus_ImageLoadFromFile($Ipath2)
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$hGui = GUICreate("Test hover", $width, $height,1,1,$WS_POPUP,$WS_EX_LAYERED)
WinSetOnTop("Test hover", "", 1)

Guisetbkcolor($transColor,$hGui)
_WinAPI_SetLayeredWindowAttributes($hGui,$transColor,255)
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
_GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage,0,0,$width,$height)
Do
;WinSetOnTop("Test hover", "", 0)
WinSetOnTop("Test hover", "", 1)
_GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage,0,0,$width,$height)
;_GDIPlus_ImageDispose($hImage)
sleep(1000)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphic)

_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_ERASENOW)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
_GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage2,0,0,$width,$height)
sleep(1000)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_ERASENOW)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
Until GUIGetMsg() = -3
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Edited by fusion400
Link to comment
Share on other sites

This is what I meant (plus code cleaned) :

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

Local $sImgPath1 = @ScriptDir & "\A.png"
Local $sImgPath2 = @ScriptDir & "\B.png"

Local Const $iTransColor = 0xABCDEF

_GDIPlus_Startup()

Local $hImage1 = 0, $hImage2 = 0, $iWidth = 0, $iHeight = 0

$hImage1 = _GDIPlus_ImageLoadFromFile($sImgPath1)
$iWidth = _GDIPlus_ImageGetWidth($hImage1)
$iHeight = _GDIPlus_ImageGetHeight($hImage1)

$hImage2 = _GDIPlus_ImageLoadFromFile($sImgPath2)

Local $hGUI = GUICreate("MyGUI", $iWidth, $iHeight, 1, 1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetBkColor($iTransColor, $hGUI)
_WinAPI_SetLayeredWindowAttributes($hGUI, $iTransColor, 255)
GUISetState()

$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)

Do
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage1, 0, 0, $iWidth, $iHeight)
    Sleep(1000)
    _WinAPI_RedrawWindow($hGUI)

    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage2, 0, 0, $iWidth, $iHeight)
    Sleep(1000)
    _WinAPI_RedrawWindow($hGUI)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)

_GDIPlus_GraphicsDispose($hGraphics)

_GDIPlus_Shutdown()

Br, FireFox.

Link to comment
Share on other sites

This works great. Thanks alot.

There is sometimes though some minor gap in displaying the different pictures. Like you can see for maybe 200-300ms that there is no picture displayed. almost like a slight flickering. It does not happen all the time though.

I also noticed another problem and that is that the pictures are almost transparent there is a light 1pixel blue color outline that does not exist in photoshop. Maybe there is something else that can be done about that in GDI+?It would also be really neat to be able to fade in and fade out images. Maybe it's possible in GDI+ somehow?

Edited by fusion400
Link to comment
Share on other sites

Try this:

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

Local $sImgPath1 = @ScriptDir & "\Torus.png"
Local $sImgPath2 = @ScriptDir & "\vertical.png"

Local Const $iTransColor = 0xABCDEF

_GDIPlus_Startup()

Local $aImages[2], $iWidth = 0, $iHeight = 0, $i

$aImages[0] = _GDIPlus_ImageLoadFromFile($sImgPath1)
$aImages[1] = _GDIPlus_ImageLoadFromFile($sImgPath2)

Local $hGUI = GUICreate("", 0, 0, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetState()

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

Do
    UpdateLayeredWindow($aImages[$i], $hGUI, 1)
    Sleep(1000)
    UpdateLayeredWindow($aImages[$i], $hGUI, 0)
    $i = Mod($i + 1, 2)
Until False

Func _Exit()
    GUIDelete()
    _GDIPlus_ImageDispose($aImages[0])
    _GDIPlus_ImageDispose($aImages[1])
    _GDIPlus_Shutdown()
    Exit
EndFunc

Func UpdateLayeredWindow($hBitmap, $hGUI, $iFadeDir = 2, $iStep = 2, $iX = 0, $iY = 0, $bCenter = True)
    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    Local Const $iWidth = _GDIPlus_ImageGetWidth($hBitmap)
    Local Const $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    If $bCenter Then
        $iX = (@DesktopWidth - $iWidth) / 2
        $iY = (@DesktopHeight - $iHeight) / 2
    EndIf
    WinMove($hGUI, "", $iX, $iY)
    Local Const $hScrDC = _WinAPI_GetDC($hGUI)
    Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    Local Const $tSize = DllStructCreate($tagSIZE)
    DllStructSetData($tSize, "X", $iWidth)
    DllStructSetData($tSize, "Y", $iHeight)
    Local Const $tSource = DllStructCreate($tagPOINT)
    Local Const $tBlend = DllStructCreate($tagBLENDFUNCTION)
    DllStructSetData($tBlend, "Format", 1)
    Local $i, $hDLL = DllOpen("user32.dll")
    Switch $iFadeDir
        Case 0
            For $i = 0xFF To 0 Step -$iStep
                DllStructSetData($tBlend, "Alpha", $i)
                DllCall($hDLL, "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA)
                Sleep(10)
            Next
        Case 1
            For $i = 0 To 0xFF Step $iStep
                DllStructSetData($tBlend, "Alpha", $i)
                DllCall($hDLL, "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA)
                Sleep(10)
            Next
        Case 2
            DllStructSetData($tBlend, "Alpha", 0xFF)
            DllCall($hDLL, "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA)
    EndSwitch
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_DeleteObject($hHBitmap)
    _WinAPI_DeleteDC($hMemDC)
    DllClose($hDLL)
EndFunc

Br,

UEZ

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

Link to comment
Share on other sites

Everything is possible! The challenge is to find the way...

Check out post#7.

Br,

UEZ ;)

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

Link to comment
Share on other sites

The fadein and fadeouts works very well and it's extremely smooth with barely no cpu usage either.

Truly amazing that it can be done in autoit.

Do you know if it's possible for GDI+ to generate this text on the fly without resorting to pngs made in photoshop?

Can it draw the white outline with a 2px size just like in photoshop with the Calibri font and also antialias it?

Another neat thing would be to be able to scroll the image smoothly horizontally. Like i remember old C64 and Amiga demos that had incredible smooth scrolling and i always wondered how they were able to do it with extremely limited resources they could do text scrolling that filled the entire screen and still keep it scrolling at full 50fps/60fps. I think that they used bitmap based fonts at the time but it was still very impressive.

Link to comment
Share on other sites

Do you know if it's possible for GDI+ to generate this text on the fly without resorting to pngs made in photoshop?

I don't understand what you mean!

Can it draw the white outline with a 2px size just like in photoshop with the Calibri font and also antialias it?

Yes.

Another neat thing would be to be able to scroll the image smoothly horizontally. Like i remember old C64 and Amiga demos that had incredible smooth scrolling and i always wondered how they were able to do it with extremely limited resources they could do text scrolling that filled the entire screen and still keep it scrolling at full 50fps/60fps. I think that they used bitmap based fonts at the time but it was still very impressive.

That's possible, too.

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

Link to comment
Share on other sites

What i meant was that the program generates all the text with the same effects that was used in photoshop. So you can easily update the text maybe from an .ini file instead of having to open photoshop and change the text there and then save it to PNG again.

Edited by fusion400
Link to comment
Share on other sites

Yes, that's easy to realize with GDI+, too. Do you want to generate the text and save it or only displaying it in a GUI?

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

Link to comment
Share on other sites

Here a different example than from the help file:

;coded by UEZ 2013-04-26
#include <GDIPlus.au3>
_GDIPlus_Startup()

Global $iW = 650, $iH = 210, $aResult
Global Const $hGUI = GUICreate("Test", $iW, $iH)
GUISetBkColor(0xFFFFFF)
GUISetState()

Global Const $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global Const $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Global Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 2)
_GDIPlus_GraphicsSetTextRenderingHint($hCtxt, 4)
_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)

$aResult = _GDIPlus_DrawText($hCtxt, @ComputerName, 40, 20, 15, "Arial", 0xF00000FF, 0x80808020)
$aResult = _GDIPlus_DrawText($hCtxt, "Online", 40, $aResult[0] + $aResult[2] + 40, 15, "Arial", 0xF000FF00, 0xA8A0A0A0, 3)

$aResult = _GDIPlus_DrawText($hCtxt, @ComputerName, 70, 20, 120, "Arial", 0xFFFFFFFF, 0x80808020, 0.75, 3)
$aResult = _GDIPlus_DrawText($hCtxt, "Offline", 70, $aResult[0] + $aResult[2] + 40, 120, "Arial", 0xFFFF0000, 0xA8808080, 3, 1)

_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Text.png")

Do
    If GUIGetMsg() = -3 Then
        _GDIPlus_GraphicsDispose($hCtxt)
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_Shutdown()
        GUIDelete()
        Exit
    EndIf
Until False

Func _GDIPlus_DrawText($hGraphics, $sText, $fFontSize, $iX = 0, $iY = 0, $sFontName = "Arial", $iFGColor = 0xFF0000FF, $iBGColor = 0xF8FFFFFF, $fStretch = 1, $iPenSize = 1) ;coded by UEZ 2013
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFontName)
    Local Const $hPath = _GDIPlus_PathCreate()
    Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local Const $hLineBrush = _GDIPlus_LineBrushCreate(0, 0, 20, 4, 0x80000000, $iBGColor, 1)
    Local Const $hPen = _GDIPlus_PenCreate2($hLineBrush, $iPenSize)
    Local Const $fRad = ACos(-1) / 180
    Local $i
    For $i = 1 To 360 Step 90
        DllStructSetData($tLayout, "X", $iX + Cos($i * $fRad))
        DllStructSetData($tLayout, "Y", $iY + Sin($i * $fRad))
        _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $fFontSize, $hFormat)
    Next
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen)
    Local $aWorldBounds = _GDIPlus_PathGetWorldBounds($hPath)
    _GDIPlus_PathReset($hPath)
    Local Const $iFGColorShift = 0xFF000000 + BitShift(BitAND($iFGColor, 0xFF0000), 1) + BitShift(BitAND($iFGColor, 0xFF00), 1) + BitShift(BitAND($iFGColor, 0xFF), 1) ;half RGB color values
    Local Const $hBrush = _GDIPlus_LineBrushCreate(0, 0, $aWorldBounds[2] * $fStretch, $aWorldBounds[3] * 1.5, $iFGColorShift, $iFGColor, 1)
    _GDIPlus_LineBrushSetGammaCorrection($hBrush, True)
    DllStructSetData($tLayout, "X", $iX)
    DllStructSetData($tLayout, "Y", $iY)
    _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $fFontSize, $hFormat)
    _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush)
    $aWorldBounds = _GDIPlus_PathGetWorldBounds($hPath)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hLineBrush)
    _GDIPlus_PathDispose($hPath)
    Return $aWorldBounds
EndFunc   ;==>_GDIPlus_DrawText

#region GDIP.au3 functions
Func _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen = 0)
    Local $iTmpErr, $iTmpExt, $aResult
    __GDIPlus_PenDefCreate($hPen)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipDrawPath", "handle", $hGraphics, "handle", $hPen, "handle", $hPath)
    $iTmpErr = @error
    $iTmpExt = @extended
    __GDIPlus_PenDefDispose()
    If $iTmpErr Then Return SetError($iTmpErr, $iTmpExt, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsDrawPath

Func _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush = 0)
    Local $iTmpErr, $iTmpExt, $aResult
    __GDIPlus_BrushDefCreate($hBrush)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipFillPath", "handle", $hGraphics, "handle", $hBrush, "handle", $hPath)
    $iTmpErr = @error
    $iTmpExt = @extended
    __GDIPlus_BrushDefDispose()
    If $iTmpErr Then Return SetError($iTmpErr, $iTmpExt, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsFillPath

Func _GDIPlus_GraphicsSetPixelOffsetMode($hGraphics, $iPixelOffsetMode)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetPixelOffsetMode", "handle", $hGraphics, "int", $iPixelOffsetMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetPixelOffsetMode

Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hGraphics, "int", $iTextRenderingHint)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetTextRenderingHint

Func _GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily = 0, $iStyle = 0, $nSize = 8.5, $hFormat = 0)
    Local $pLayout, $aResult
    $pLayout = DllStructGetPtr($tLayout)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipAddPathString", "handle", $hPath, "wstr", $sString, "int", -1, "handle", $hFamily, "int", $iStyle, "float", $nSize, "ptr", $pLayout, "handle", $hFormat)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_PathAddString

Func _GDIPlus_PathCreate($iFillMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", $iFillMode, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_PathCreate

Func _GDIPlus_PathDispose($hPath)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeletePath", "handle", $hPath)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_PathDispose

Func _GDIPlus_PathGetWorldBounds($hPath, $hMatrix = 0, $hPen = 0)
    Local $tRectF, $pRectF, $iI, $aRectF[4], $aResult
    $tRectF = DllStructCreate($tagGDIPRECTF)
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "handle", $hPath, "ptr", $pRectF, "handle", $hMatrix, "handle", $hPen)
    If @error Then Return SetError(@error, @extended, -1)
    If $aResult[0] Then Return -1
    For $iI = 1 To 4
        $aRectF[$iI - 1] = DllStructGetData($tRectF, $iI)
    Next
    Return $aRectF
EndFunc   ;==>_GDIPlus_PathGetWorldBounds

Func _GDIPlus_PathReset($hPath)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipResetPath", "handle", $hPath)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_PathReset

Func _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2, $iWrapMode = 0)
    Local $tPointF1, $pPointF1
    Local $tPointF2, $pPointF2
    Local $aResult
    $tPointF1 = DllStructCreate("float;float")
    $pPointF1 = DllStructGetPtr($tPointF1)
    $tPointF2 = DllStructCreate("float;float")
    $pPointF2 = DllStructGetPtr($tPointF2)
    DllStructSetData($tPointF1, 1, $nX1)
    DllStructSetData($tPointF1, 2, $nY1)
    DllStructSetData($tPointF2, 1, $nX2)
    DllStructSetData($tPointF2, 2, $nY2)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iARGBClr1, "uint", $iARGBClr2, "int", $iWrapMode, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_LineBrushCreate

Func _GDIPlus_PenCreate2($hBrush, $nWidth = 1, $iUnit = 2)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePen2", "handle", $hBrush, "float", $nWidth, "int", $iUnit, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[4]
EndFunc   ;==>_GDIPlus_PenCreate2

Func _GDIPlus_LineBrushSetGammaCorrection($hLineGradientBrush, $fUseGammaCorrection = True)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetLineGammaCorrection", "handle", $hLineGradientBrush, "int", $fUseGammaCorrection)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_LineBrushSetGammaCorrection
#endregion

Additional GDI+ functions taken from GDIP.au3.

Br,

UEZ

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

Link to comment
Share on other sites

  • 2 weeks later...

Here a different example than from the help file:

;coded by UEZ 2013-04-26
#include <GDIPlus.au3>
_GDIPlus_Startup()

Global $iW = 650, $iH = 210, $aResult
Global Const $hGUI = GUICreate("Test", $iW, $iH)
GUISetBkColor(0xFFFFFF)
GUISetState()

Global Const $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global Const $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Global Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 2)
_GDIPlus_GraphicsSetTextRenderingHint($hCtxt, 4)
_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)

$aResult = _GDIPlus_DrawText($hCtxt, @ComputerName, 40, 20, 15, "Arial", 0xF00000FF, 0x80808020)
$aResult = _GDIPlus_DrawText($hCtxt, "Online", 40, $aResult[0] + $aResult[2] + 40, 15, "Arial", 0xF000FF00, 0xA8A0A0A0, 3)

$aResult = _GDIPlus_DrawText($hCtxt, @ComputerName, 70, 20, 120, "Arial", 0xFFFFFFFF, 0x80808020, 0.75, 3)
$aResult = _GDIPlus_DrawText($hCtxt, "Offline", 70, $aResult[0] + $aResult[2] + 40, 120, "Arial", 0xFFFF0000, 0xA8808080, 3, 1)

_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Text.png")

Do
    If GUIGetMsg() = -3 Then
        _GDIPlus_GraphicsDispose($hCtxt)
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_Shutdown()
        GUIDelete()
        Exit
    EndIf
Until False

Func _GDIPlus_DrawText($hGraphics, $sText, $fFontSize, $iX = 0, $iY = 0, $sFontName = "Arial", $iFGColor = 0xFF0000FF, $iBGColor = 0xF8FFFFFF, $fStretch = 1, $iPenSize = 1) ;coded by UEZ 2013
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFontName)
    Local Const $hPath = _GDIPlus_PathCreate()
    Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local Const $hLineBrush = _GDIPlus_LineBrushCreate(0, 0, 20, 4, 0x80000000, $iBGColor, 1)
    Local Const $hPen = _GDIPlus_PenCreate2($hLineBrush, $iPenSize)
    Local Const $fRad = ACos(-1) / 180
    Local $i
    For $i = 1 To 360 Step 90
        DllStructSetData($tLayout, "X", $iX + Cos($i * $fRad))
        DllStructSetData($tLayout, "Y", $iY + Sin($i * $fRad))
        _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $fFontSize, $hFormat)
    Next
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen)
    Local $aWorldBounds = _GDIPlus_PathGetWorldBounds($hPath)
    _GDIPlus_PathReset($hPath)
    Local Const $iFGColorShift = 0xFF000000 + BitShift(BitAND($iFGColor, 0xFF0000), 1) + BitShift(BitAND($iFGColor, 0xFF00), 1) + BitShift(BitAND($iFGColor, 0xFF), 1) ;half RGB color values
    Local Const $hBrush = _GDIPlus_LineBrushCreate(0, 0, $aWorldBounds[2] * $fStretch, $aWorldBounds[3] * 1.5, $iFGColorShift, $iFGColor, 1)
    _GDIPlus_LineBrushSetGammaCorrection($hBrush, True)
    DllStructSetData($tLayout, "X", $iX)
    DllStructSetData($tLayout, "Y", $iY)
    _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $fFontSize, $hFormat)
    _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush)
    $aWorldBounds = _GDIPlus_PathGetWorldBounds($hPath)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hLineBrush)
    _GDIPlus_PathDispose($hPath)
    Return $aWorldBounds
EndFunc ;==>_GDIPlus_DrawText

#region GDIP.au3 functions
Func _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen = 0)
    Local $iTmpErr, $iTmpExt, $aResult
    __GDIPlus_PenDefCreate($hPen)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipDrawPath", "handle", $hGraphics, "handle", $hPen, "handle", $hPath)
    $iTmpErr = @error
    $iTmpExt = @extended
    __GDIPlus_PenDefDispose()
    If $iTmpErr Then Return SetError($iTmpErr, $iTmpExt, False)
    Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsDrawPath

Func _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush = 0)
    Local $iTmpErr, $iTmpExt, $aResult
    __GDIPlus_BrushDefCreate($hBrush)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipFillPath", "handle", $hGraphics, "handle", $hBrush, "handle", $hPath)
    $iTmpErr = @error
    $iTmpExt = @extended
    __GDIPlus_BrushDefDispose()
    If $iTmpErr Then Return SetError($iTmpErr, $iTmpExt, False)
    Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsFillPath

Func _GDIPlus_GraphicsSetPixelOffsetMode($hGraphics, $iPixelOffsetMode)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetPixelOffsetMode", "handle", $hGraphics, "int", $iPixelOffsetMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsSetPixelOffsetMode

Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hGraphics, "int", $iTextRenderingHint)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsSetTextRenderingHint

Func _GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily = 0, $iStyle = 0, $nSize = 8.5, $hFormat = 0)
    Local $pLayout, $aResult
    $pLayout = DllStructGetPtr($tLayout)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipAddPathString", "handle", $hPath, "wstr", $sString, "int", -1, "handle", $hFamily, "int", $iStyle, "float", $nSize, "ptr", $pLayout, "handle", $hFormat)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_PathAddString

Func _GDIPlus_PathCreate($iFillMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", $iFillMode, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc ;==>_GDIPlus_PathCreate

Func _GDIPlus_PathDispose($hPath)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeletePath", "handle", $hPath)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_PathDispose

Func _GDIPlus_PathGetWorldBounds($hPath, $hMatrix = 0, $hPen = 0)
    Local $tRectF, $pRectF, $iI, $aRectF[4], $aResult
    $tRectF = DllStructCreate($tagGDIPRECTF)
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "handle", $hPath, "ptr", $pRectF, "handle", $hMatrix, "handle", $hPen)
    If @error Then Return SetError(@error, @extended, -1)
    If $aResult[0] Then Return -1
    For $iI = 1 To 4
        $aRectF[$iI - 1] = DllStructGetData($tRectF, $iI)
    Next
    Return $aRectF
EndFunc ;==>_GDIPlus_PathGetWorldBounds

Func _GDIPlus_PathReset($hPath)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipResetPath", "handle", $hPath)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_PathReset

Func _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2, $iWrapMode = 0)
    Local $tPointF1, $pPointF1
    Local $tPointF2, $pPointF2
    Local $aResult
    $tPointF1 = DllStructCreate("float;float")
    $pPointF1 = DllStructGetPtr($tPointF1)
    $tPointF2 = DllStructCreate("float;float")
    $pPointF2 = DllStructGetPtr($tPointF2)
    DllStructSetData($tPointF1, 1, $nX1)
    DllStructSetData($tPointF1, 2, $nY1)
    DllStructSetData($tPointF2, 1, $nX2)
    DllStructSetData($tPointF2, 2, $nY2)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iARGBClr1, "uint", $iARGBClr2, "int", $iWrapMode, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
EndFunc ;==>_GDIPlus_LineBrushCreate

Func _GDIPlus_PenCreate2($hBrush, $nWidth = 1, $iUnit = 2)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePen2", "handle", $hBrush, "float", $nWidth, "int", $iUnit, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[4]
EndFunc ;==>_GDIPlus_PenCreate2

Func _GDIPlus_LineBrushSetGammaCorrection($hLineGradientBrush, $fUseGammaCorrection = True)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetLineGammaCorrection", "handle", $hLineGradientBrush, "int", $fUseGammaCorrection)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_LineBrushSetGammaCorrection
#endregion

Additional GDI+ functions taken from GDIP.au3.

Br,

UEZ

Thanks alot UEZ works great :)
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...