Jump to content



Photo

GDIP.au3


  • Please log in to reply
32 replies to this topic

#1 Authenticity

Authenticity

    Universalist

  • MVPs
  • 2,619 posts

Posted 27 November 2009 - 11:45 PM

I'd like to list the following resources which I've found very useful, most of this is from there:

GDI+ Classes
José Roca's GDI+ reference and forum
developpez, a french site but with in-depth explanation.
And a warm thanks to Sjaak Priester for his wonderful ColorMatrix tool and source which the ColorMatrix funtions are built on.

I've forgot ;), thanks to Paul Campbell (PaulIA) for the great UDF, Malkey, UEZ, trancexx, monoceres, and everybody else for posting generous GDI+ examples.

This UDF is just a wrapper around GDIPlus.au3 to include the rest of the exports.

Notes about error handling:
There exist two additional status variables to catch function status or error codes. $GDIP_STATUS contains the return value from the function and it's meaning can be examined in GDIPlusConstants.au3 for a short description. A few functions may also set $GDIP_ERROR variable to a value explained in the function description. This variable should be contained in conditional code only when it's set by the GDIPlus functions as $GDIP_ERROR is never cleared, only set on error.

Currently:
Spoiler


I've included a few examples, mostly the useless ones but it's because it's the hardest part to sit and write meaningful examples, even for the simplest functions. :)

Edit: Special thanks to all the contributes. B)

History:
Plain Text         
Update 27.12.2010:  - Removed various constants declared by other UDFs. Update 11.12.2010:  - Removed _WinAPI_* functions from UDF (thanks ProgAndy).    Examples that rely on these functions define them. Update 03.08.2010:  - Added _GDIPlus_FontFamilyCreate2. (thanks Yashied)  - Fixed _GDIPlus_PrivateFontCollectionDispose. (thanks Yashied)  - Updated user call-tips and functions highlight. Update 13.07.2010:  - Added a few examples that are somewhat related to GDI+.  - Fixed some of the image frame functions. Update 06.06.2010:  - Fixed _GDIPlus_PathAddRectangles function. Update 03.06.2010:  - Fixed GDIP.au3, now compatible with AutoIt v3.3.6.1.  - Fixed _GDIPlus_PathWarp function. Thank you eukalyptus for the catch. Update 12.12.2009:  - Fixed several examples and their counterpart functions, as required. Update 11.12.2009:  - Added a few more examples to the ImageAttributes object functions.  - Fixed _GDIPlus_ImageAttributesSetNoOp function description.  - Fixed _GDIPlus_BitmapCreateFromStreamICM function description and call tip. Update 06.12.2009:  - Added a few ColorMatrix manipulation functions, see top of the page for acknowledges.  - Added a few more examples to the ImageAttribute object. Update 04.12.2009:  - Added a few more examples for InstalledCollection, Graphics, GraphicsContainer.  - Fixed _GDIPlus_GraphicsDrawRectangles and _GDIPlus_GraphicsFillRectangles functions  - Fixed a few examples that used some old functions syntax Update 03.12.2009:  - Added function descriptions.  - A few function definitions have been redefined to be consistent with return and parameters values.  - No additional examples at the moment.

Attached Files

  • Attached File  GDIP.7z   495.28K   2620 downloads

Edited by Authenticity, 27 December 2010 - 07:32 AM.






#2 UEZ

UEZ

    Never say never

  • MVPs
  • 3,605 posts

Posted 27 November 2009 - 11:59 PM

Great extensions of GDI+ library!

Maybe now dreams come true... :)

Thanks for sharing!

UEZ

PS: 5* from me for your efforts

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#3 trancexx

trancexx

    Hm, I really shouldn't.

  • Active Members
  • PipPipPipPipPipPip
  • 5,191 posts

Posted 29 November 2009 - 03:24 PM

Nice. When you add descriptions it would be much nicer.

There is one thing I don't understand. It's:


I can see how could that be useful when you look to the future or whatever. But only with eyes closed.
That technique shouldn't be considered as a final solution.
Even though it seems smart, usually it's adding more confusion when debugging than it should. If the function is complex one (more than one DllCall) it's almost impossible to determine what's failing.
For example you have function _GDIPlus_FontCollectionGetFamilyList().
Let's say it fails for some reason. You check @error and it's 3. You check @extended and it's 0.
What failed?

Wouldn't be much better to do something like this?
If @error Then Return SetError($iRelativeErrorPosition, @error, 0)

Where $iRelativeErrorPosition would be number that would uniquely identify position of error inside the function.

Will wait for description of functions before rating it fairly :) .

eMyvnE


#4 Uriziel01

Uriziel01

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 281 posts

Posted 29 November 2009 - 06:45 PM

PLEASE !! Can you give me an working example of using _GDIPlus_TextureRotateTransform or _GDIPlus_ImageRotateFlip function with .png image. Im now working on some project and using normal matrix transform is horrible (it is rotating entire graphics content [I mean the size of entire GC] not only my image, and calculating new position of image is some nightmare), Thank You ! :)
BTW those funcitons are really really great ! I hope that the can be implemented in some ne comming BETA some days ;)

Edited by Uriziel01, 29 November 2009 - 06:53 PM.

Posted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted Image

#5 Authenticity

Authenticity

    Universalist

  • MVPs
  • 2,619 posts

Posted 29 November 2009 - 07:37 PM

Nice. When you add descriptions it would be much nicer.

There is one thing I don't understand. It's:


...
Let's say it fails for some reason. You check @error and it's 3. You check @extended and it's 0.
What failed?

Wouldn't be much better to do something like this?
If @error Then Return SetError($iRelativeErrorPosition, @error, 0)
Where $iRelativeErrorPosition would be number that would uniquely identify position of error inside the function.
...

Thanks for the tips. You're absolutely right and I know that, you can see somewhere in the functions definitions something like:
If $iData = 0 The Return SetError(1, 1, 0)

..or returning -1 but it'll not be the final solution. Yes I'm a bit lazy in my nature but when things need to be done, they'll be done sometime.
The most problematic thing about it is to find a uniform way not to make the Remarks and Return sections redundant with if that then that, anyway I'm now working on the function decoration and rewriting the code as necessary. Funny thing, at the end the decorations are going to triple the file size from 3k lines to 9k+ lines :) Just as my first post, it wasn't and isn't complete. Thanks again for the suggestions.

P.S. I'm not expecting a starting scripter to walk through each and every error possibility or even use error handling at all so if the user is using it, the user probably knows what may be wrong but this is not an excuse to write a bad function.

PLEASE !! Can you give me an working example of using _GDIPlus_TextureRotateTransform or _GDIPlus_ImageRotateFlip function with .png image. Im now working on some project and using normal matrix transform is horrible (it is rotating entire graphics content [I mean the size of entire GC] not only my image, and calculating new position of image is some nightmare), Thank You ! ;)
BTW those funcitons are really really great ! I hope that the can be implemented in some ne comming BETA some days B)

Link. Search José Roca's forum, you'll find examples for almost any function exported via GDI+, most of the examples, eventually, will be taken from there. Read the PowerBASIC code, it's closer to AutoIt than the C++ one.


Edit: You! B) Now I need to manage 4 different states... Is $GDIP_STATUS and $GDIP_ERROR in conjunction with @error and @extended sounds sufficient?. $GDIP_STATUS is set to the return value (if DllCall didn't fail) of the function when applicable, $GDIP_ERROR will be set to 0 always and to an increasing integer that specifies the nested GDI+ function that failed. Comments?

Edited by Authenticity, 29 November 2009 - 08:58 PM.


#6 UEZ

UEZ

    Never say never

  • MVPs
  • 3,605 posts

Posted 06 December 2009 - 02:43 PM

Here an example with _GDIPlus_HatchBrushCreate() function (53 fill patterns):

Nothing special but imho worth mentioning.

AutoIt         
;Coded by UEZ 2009.12.06 #include <GDIplus.au3> Opt("GUIOnEventMode", 1) _GDIPlus_Startup() Global $width = @DesktopWidth * 0.75 Global $height = @DesktopHeight * 0.75 Global $hwnd = GUICreate("GDI+: Filled Brushes by UEZ", $width, $height, -1, -1, Default) GUISetOnEvent(-3, "_Exit") GUISetState() Global $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd) _GDIPlus_GraphicsSetSmoothingMode($graphics, 4) Global $brush[53] For $i = 0 To UBound($brush) - 1     $brush[$i] = _GDIPlus_HatchBrushCreate($i, 0xFF0000FF, 0xFFFFFFFF) Next $dx = Int($width / 8) $dy = Int($height / 7) _GDIPlus_GraphicsClear($graphics, 0xFF000000) $k = 0 For $i = 0 To $height -1 Step $dy     For $j = 0 To $width - 1 Step $dx         If $k <= UBound($brush) -1 Then _GDIPlus_GraphicsFillEllipse($graphics, $j, $i, $dx, $dy, $brush[$k])         $k += 1     Next Next While Sleep(150) WEnd Func _Exit()     For $i = 0 To UBound($brush) - 1         _GDIPlus_BrushDispose($brush[$i])     Next     _GDIPlus_GraphicsDispose($graphics)     _GDIPlus_Shutdown()     Exit EndFunc Func _GDIPlus_HatchBrushCreate($iHatchStyle = 0, $iARGBForeground = 0xFFFFFFFF, $iARGBBackground = 0xFFFFFFFF)     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateHatchBrush", "int", $iHatchStyle, "uint", $iARGBForeground, "uint", $iARGBBackground, "int*", 0)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, $aResult[4]) EndFunc ;==>_GDIPlus_HatchBrushCreate


Thanks to Authenticity for the additional GDI+ function. Currently I'm searching within the functions for some nice functions...


Have a nice Santa Claus

UEZ

Edited by UEZ, 06 December 2009 - 03:42 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#7 Authenticity

Authenticity

    Universalist

  • MVPs
  • 2,619 posts

Posted 06 December 2009 - 07:55 PM

w00t :) Thanks for the example, better than what I could come up with, for sure.

Here is a little translated tool original written by Sjaak Priester. I've just translated it (not so good) but it's still good to show the ColorMatrix functions meaning:
AutoIt         
#include <Constants.au3> #include <GDIP.au3> #include <GUIConstantsEx.au3> #include <ScrollBarConstants.au3> #include <GUIToolbar.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) If Not IsDeclared("SB_ENDSCROLL") Then Global Const $SB_ENDSCROLL = 8 Global $hToolbar Global Enum $idOpen = 0x0400, $idSave Global $aLables[5] = ["Contrast", "Brightness", "Saturation", "Hue", "Gamma"] ; Slider, hSlider, Label, Min, Max, Default, Factor, Precision, PreviousVal Global $aSliders[5][9] = _    [[0, 0, 0, 4, 80, 20, 0.05, 2, -1], _     [0, 0, 0, -20, 20, 0, 0.05, 2, -1], _     [0, 0, 0, 0, 60, 20, 0.05, 2, -1], _     [0, 0, 0, -45, 45, 0, 4, 0, -1], _     [0, 0, 0, 4, 80, 20, 0.05, 2, -1]]     Global $hGraphics, $hImage, $hBackImage, $hImageContext, $hIA, $tPreHue, $tPostHue, $aImageSize, $sImage, $iPicWidth, $iPicHeight, $fChange Global $sImageFormats = "All Picture Files (*.bmp;*.gif;*.jpg;*.jpeg;*.jpe;*.jfif;*.tif;*.tiff;*.png;*.exif;*.wmf;*.emf)" _GDIPlus_Startup() _Main() _GDIPlus_Shutdown() Func _Main()     Local $hGUI, $BtnReset, $BtnBlackWhite, $iGUIWidth, $iGUIHeight, $iLeft, $iTop, $iI, $aSize         $iGUIWidth = @DesktopWidth*0.75     $iGUIHeight = @DesktopHeight*0.75         If $iGUIWidth < 900 Then $iGUIWidth = 900     If $iGUIHeight < 700 Then $iGUIHeight = 700     $hGUI = GUICreate("Image tool", $iGUIWidth, $iGUIHeight)     $hToolbar = _GUICtrlToolbar_Create ($hGUI)     $aSize = _GUICtrlToolbar_GetMaxSize ($hToolbar)             $iPicWidth = $iGUIWidth-250     $iPicHeight = $iGUIHeight - $aSize[1] - 30     GUICtrlCreateLabel("", 10, $aSize[1] + 20, $iPicWidth, $iPicHeight, -1, $WS_EX_CLIENTEDGE)     $hGraphics = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle(-1))     $hIA = _GDIPlus_ImageAttributesCreate()         _GDIPlus_GraphicsSetInterpolationMode($hGraphics, 7)         $iLeft = $iGUIWidth - 230     $iTop = $aSize[1]+20         For $iI = 0 To UBound($aSliders)-1         GUICtrlCreateLabel($aLables[$iI], $iLeft, $iI*60+$iTop)         $aSliders[$iI][0] = GUICtrlCreateSlider($iLeft, $iI*60+$iTop+20, 150, 20)         $aSliders[$iI][1] = GUICtrlGetHandle(-1)         $aSliders[$iI][2] = GUICtrlCreateLabel("", $iLeft+160, $iI*60+$iTop+20, 40, 25)         GUICtrlSetLimit($aSliders[$iI][0], $aSliders[$iI][4], $aSliders[$iI][3])     Next         _Reset()     $BtnReset = GUICtrlCreateButton("Reset", $iLeft+125, $iI*60+$iTop, 70, 25)     $BtnBlackWhite = GUICtrlCreateButton("Black&&White", $iLeft+50, $iI*60+$iTop, 70, 25)         _GUICtrlToolbar_AddBitmap ($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)     _GUICtrlToolbar_AddButton ($hToolbar, $idOpen, $STD_FILEOPEN)     _GUICtrlToolbar_AddButton ($hToolbar, $idSave, $STD_FILESAVE)     GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")     GUIRegisterMsg($WM_HSCROLL, "_WM_HSCROLL")     GUISetState()         While 1         Switch GUIGetMsg()             Case $BtnReset                 _Reset()                             Case $BtnBlackWhite                 _BlackAndWhite()                         Case $GUI_EVENT_RESTORE                 If $hImage Then _Update()                             Case $GUI_EVENT_CLOSE                 If $fChange Then                     If _Save() Then                         If $hImageContext Then _GDIPlus_GraphicsDispose($hImageContext)                         If $hBackImage Then _GDIPlus_ImageDispose($hBackImage)                         If $hImage Then _GDIPlus_ImageDispose($hImage)                         _GDIPlus_ImageAttributesDispose($hIA)                         _GDIPlus_GraphicsDispose($hGraphics)                         ExitLoop                     EndIf                 Else                     ExitLoop                 EndIf         EndSwitch     WEnd EndFunc Func _Reset()     Local $iI         For $iI = 0 To UBound($aSliders)-1          GUICtrlSetData($aSliders[$iI][2], _GetStringFormat($iI, $aSliders[$iI][5]))         GUICtrlSetData($aSliders[$iI][0], $aSliders[$iI][5])         $aSliders[$iI][8] = -1     Next         _GDIPlus_ImageAttributesSetThreshold($hIA, 0, False)     If $hImage Then _Update() EndFunc Func _Save()     Local $iRet         If $fChange Then         $iRet = MsgBox(0x23, "Save changes", 'Would you like to save changes to "' & StringTrimLeft($sImage, StringInStr($sImage, "\", 0, -1)) & '"?')                 If $iRet = 2 Then             Return False         ElseIf $iRet = 6 Then             _GDIPlus_ImageSaveToFile($hBackImage, $sImage)         EndIf     EndIf         Return True EndFunc Func _Initialize()     $tPreHue = _GDIPlus_ColorMatrixCreate()     $tPostHue = _GDIPlus_ColorMatrixCreate()     _GDIPlus_ColorMatrixInitHue($tPreHue, $tPostHue)             $aImageSize = _GDIPlus_ImageGetDimension($hImage)     _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iPicWidth, $iPicHeight)     _Reset()     $fChange = False EndFunc Func _Update()     Local $tColorMatrix, $pColorMatrix, $nContrast, $nBrightness, $nSaturation, $nHue, $nGamma         $tColorMatrix = _GDIPlus_ColorMatrixCreate()     $pColorMatrix = DllStructGetPtr($tColorMatrix)         $nContrast = _GetValue(0)     $nBrightness = _GetValue(1)     $nSaturation = _GetValue(2)     $nHue = _GetValue(3)     $nGamma = _GetValue(4)         _GDIPlus_ColorMatrixScale($tColorMatrix, $nContrast, $nContrast, $nContrast, 1, 1)     _GDIPlus_ColorMatrixTranslate($tColorMatrix, $nBrightness, $nBrightness, $nBrightness, 0, 1)     _GDIPlus_ColorMatrixSetSaturation($tColorMatrix, $nSaturation, 1)     _GDIPlus_ColorMatrixRotateHue($tColorMatrix, $tPreHue, $tPostHue, $nHue)         _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pColorMatrix)     _GDIPlus_ImageAttributesSetGamma($hIA, 0, True, $nGamma)         _GDIPlus_GraphicsDrawImageRectRectIA($hImageContext, $hImage, 0, 0, $aImageSize[0], $aImageSize[1], 0, 0, $aImageSize[0], $aImageSize[1], $hIA)     _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBackImage, 0, 0, $aImageSize[0], $aImageSize[1], 0, 0, $iPicWidth, $iPicHeight) EndFunc Func _GetValue($iIndex)     Return GUICtrlRead($aSliders[$iIndex][0])*$aSliders[$iIndex][6] EndFunc Func _GetStringFormat($iIndex, $iVal)     If $aSliders[$iIndex][7] Then         Return StringFormat("%." & $aSliders[$iIndex][7] & "f", $iVal*$aSliders[$iIndex][6])     Else         Return StringFormat("%d", $iVal*$aSliders[$iIndex][6])     EndIf EndFunc Func _BlackAndWhite()     Local $tBWMatrix, $pBWMatrix         If $hImage Then         _GDIPlus_ImageAttributesSetThreshold($hIA, 0, True, 0.5)         $tBWMatrix = _GDIPlus_ColorMatrixCreateGrayScale()         $pBWMatrix = DllStructGetPtr($tBWMatrix)                 _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pBWMatrix)         _GDIPlus_GraphicsDrawImageRectRectIA($hImageContext, $hImage, 0, 0, $aImageSize[0], $aImageSize[1], 0, 0, $aImageSize[0], $aImageSize[1], $hIA)         _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBackImage, 0, 0, $aImageSize[0], $aImageSize[1], 0, 0, $iPicWidth, $iPicHeight)         $fChange = True     EndIf EndFunc Func _WM_HSCROLL($hWnd, $iMsg, $iwParam, $ilParam)     Local $iI, $iPos, $iCode         $iCode = BitAND($iwParam, 0xFFFF)     If $iCode = $SB_ENDSCROLL Or $iCode = $SB_THUMBPOSITION Then Return 0         For $iI = 0 To UBound($aSliders)-1         If $aSliders[$iI][1] = $ilParam Then             $iPos = GUICtrlRead($aSliders[$iI][0])                         If $iPos <> $aSliders[$iI][8] Then                 GUICtrlSetData($aSliders[$iI][2], _GetStringFormat($iI, $iPos))                 $aSliders[$iI][8] = $iPos                                 If $hImage Then                     $fChange = True                     _Update()                 EndIf             EndIf             ExitLoop         EndIf     Next       Return $GUI_RUNDEFMSG EndFunc Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)     Local $tNMHDR, $hFrom, $iCode,  $iCommand, $sFileName, $sFile, $sExt, $sTmp, $hBitmap, $hContext         $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)     $hFrom = DllStructGetData($tNMHDR, "hWndFrom")     $iCode = DllStructGetData($tNMHDR, "Code")         If $hFrom = $hToolbar And $iCode = $NM_LDOWN Then         Local $iCommand = _GUICtrlToolbar_IndexToCommand($hToolbar, _GUICtrlToolbar_GetHotItem($hToolbar))                 Switch $iCommand             Case $idOpen                 $sFileName = FileOpenDialog("Open File", @WorkingDir, $sImageFormats, 3)                                     If $sFileName Then                     If _Save() Then                         $sImage = $sFileName                                                 If $hImage Then                             _GDIPlus_GraphicsDispose($hImageContext)                             _GDIPlus_ImageDispose($hBackImage)                             _GDIPlus_ImageDispose($hImage)                             $hImage = 0                             $hBackImage = 0                             $hImageContext = 0                             $sImage = ""                         EndIf                                                 $hBitmap = _GDIPlus_ImageLoadFromFile($sFileName)                         If @error Then                             MsgBox(0x10, "Error", "Could not load image")                             _Reset()                             $fChange = False                         Else                             $hImage = _GDIPlus_BitmapCreateFromScan0(_GDIPlus_ImageGetWidth($hBitmap), _GDIPlus_ImageGetHeight($hBitmap))                             $hContext = _GDIPlus_ImageGetGraphicsContext($hImage)                             _GDIPlus_GraphicsDrawImage($hContext, $hBitmap, 0, 0)                             _GDIPlus_GraphicsDispose($hContext)                             _GDIPlus_ImageDispose($hBitmap)                             $hBackImage = _GDIPlus_ImageClone($hImage)                             $hImageContext = _GDIPlus_ImageGetGraphicsContext($hBackImage)                             _Initialize()                         EndIf                     EndIf                 EndIf             Case $idSave                 If $hImage Then                     $sFile = StringTrimLeft($sImage, StringInStr($sImage, "\", 0, -1))                     $sExt = StringTrimLeft($sFile, StringInStr($sFile, ".", 0, -1))                                         $sFileName = FileSaveDialog("Save As", @WorkingDir, $sImageFormats, 18, $sFile)                                         If $sFileName Then                         If StringRight($sFileName, StringLen($sExt)+1) <> "." & $sExt Then $sFileName &= "." & $sExt                         _GDIPlus_ImageSaveToFile($hBackImage, $sFileName)                         $fChange = False                     EndIf                 EndIf         EndSwitch     EndIf         Return $GUI_RUNDEFMSG EndFunc


..and an image for testing.

Attached Thumbnails

  • flowers.jpg

Edited by Authenticity, 06 December 2009 - 07:57 PM.

  • wakillon likes this

#8 UEZ

UEZ

    Never say never

  • MVPs
  • 3,605 posts

Posted 06 December 2009 - 08:50 PM

You did the documentation for each function - great work! :)

Continuing with analyse of some interessting GDI+ functions...

UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#9 UEZ

UEZ

    Never say never

  • MVPs
  • 3,605 posts

Posted 06 December 2009 - 09:24 PM

Unfortunately the fill functions (texture or patterns) are not as expected. It is only a static backround image and not real fill in object!

Example:

AutoIt         
;coded by UEZ 2009 #include <GUIConstantsEx.au3> #include <GDIplus.au3> #include <WindowsConstants.au3> Global Const $width = @DesktopWidth / 2 Global Const $height = @DesktopHeight / 2 Opt("GUIOnEventMode", 1) Global $hwnd = GUICreate("Border Collision!", $width, $height, -1, -1, Default, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) GUISetOnEvent($GUI_EVENT_CLOSE, "close") GUISetState() _GDIPlus_Startup() Global $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd) Global $bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics) Global $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) _GDIPlus_GraphicsClear($backbuffer) _GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4) Global $max_dots = 20 Global $max_speed = 5 Global $iWidth = 60 Global $iHeight = 60 Dim $coordinates[$max_dots][5], $angle Dim $brush[$max_dots] Initialize() Do     _GDIPlus_GraphicsClear($backbuffer, 0xFF000000)     Draw_Dots()     Calculate_New_Position()     _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)     Sleep(30) Until False Func Initialize()     For $k = 0 To $max_dots - 1         $brush[$k] = _GDIPlus_HatchBrushCreate(Random(0, 52, 1), 0xFF0000FF, 0xFFFFFFFF)         New_Coordinates($k)     Next EndFunc ;==>Initialize Func Draw_Dots()     Local $i, $temp_x, $temp_y     For $i = 0 To $max_dots - 1         _GDIPlus_GraphicsFillEllipse($backbuffer, $coordinates[$i][0], $coordinates[$i][1], $iWidth, $iHeight, $brush[$i])     Next EndFunc ;==>Draw_Dots Func New_Coordinates($k)     $coordinates[$k][0] = $width / 2 ;Random($width / 20, $width - $width / 20, 1);start x position     $coordinates[$k][1] = $height / 2 ;Random($height / 20, $height - $height / 20, 1) ;start y position     $coordinates[$k][2] = Random(1, $max_speed, 1) ;speed of pixel     $angle = Random(0, 359, 1) ;~ ConsoleWrite("Angle: " & $angle & "°" & @CRLF)     $coordinates[$k][3] = $coordinates[$k][2] * Cos($angle * 3.141592653 / 180)     $coordinates[$k][4] = $coordinates[$k][2] * Sin($angle * 3.141592653 / 180) EndFunc ;==>New_Coordinates Func Calculate_New_Position()     Local $k     For $k = 0 To $max_dots - 1         $coordinates[$k][0] += $coordinates[$k][3] ;increase x coordinate with appropriate slope         $coordinates[$k][1] += $coordinates[$k][4] ;increase y coordinate with appropriate slope         If $coordinates[$k][0] <= 0 Then ;border collision x left             $coordinates[$k][0] = 1             $coordinates[$k][3] *= -1         ElseIf $coordinates[$k][0] >= $width - $iWidth Then ;border collision x right             $coordinates[$k][0] = $width - ($iWidth + 1)             $coordinates[$k][3] *= -1         EndIf         If $coordinates[$k][1] <= 0 Then ;border collision y top             $coordinates[$k][1] = 1             $coordinates[$k][4] *= -1         ElseIf $coordinates[$k][1] >= $height - $iHeight Then ;border collision y bottom             $coordinates[$k][1] = $height - ($iHeight + 1)             $coordinates[$k][4] *= -1         EndIf     Next EndFunc ;==>Calculate_New_Position Func close()     For $k = 0 To $max_dots - 1         _GDIPlus_BrushDispose($brush[$k])     Next     _GDIPlus_BitmapDispose($bitmap)     _GDIPlus_GraphicsDispose($graphics)     _GDIPlus_GraphicsDispose($backbuffer)     _GDIPlus_Shutdown()     Exit EndFunc ;==>close Func _GDIPlus_HatchBrushCreate($iHatchStyle = 0, $iARGBForeground = 0xFFFFFFFF, $iARGBBackground = 0xFFFFFFFF)     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateHatchBrush", "int", $iHatchStyle, "uint", $iARGBForeground, "uint", $iARGBBackground, "int*", 0)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, $aResult[4]) EndFunc ;==>_GDIPlus_HatchBrushCreate


I did not find a real fill function! :)

UEZ

Edited by UEZ, 06 December 2009 - 09:25 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#10 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 06 December 2009 - 11:22 PM

I did not find a real fill function! :)

UEZ


Did you mean FloodFill GDI API?

Here is my example for that:
http://www.autoitscript.com/forum/index.php?s=&showtopic=45978&view=findpost&p=344974

#11 UEZ

UEZ

    Never say never

  • MVPs
  • 3,605 posts

Posted 06 December 2009 - 11:46 PM

Can I fill e.g. an area (in your example) with a texture (image) whereas the texture matches the area?

UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#12 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 06 December 2009 - 11:55 PM

This UDF is just a wrapper around GDIPlus.au3 to include the rest of the exports.

History:

Update 06.12.2009:  - Added a few ColorMatrix manipulation functions, see top of the page for acknowledges.  - Added a few more examples to the ImageAttribute object. Update 04.12.2009:  - Added a few more examples for InstalledCollection, Graphics, GraphicsContainer.  - Fixed _GDIPlus_GraphicsDrawRectangles and _GDIPlus_GraphicsFillRectangles functions  - Fixed a few examples that used some old functions syntax Update 03.12.2009:  - Added function descriptions.  - A few function definitions have been redefined to be consistent with return and parameters values.  - No additional examples at the moment.

Thanks for sharing!
You have done big good work.
With all standard description headers you can add it as proposition for adding to standard includes, just make ticket for it on Trac.
I think lack of examples for all included functions is not problem here. There are many standard UDFs without examples already.
I'm looking forward to new Autoit's beta with this included :-)

#13 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 07 December 2009 - 12:06 AM

Can I fill e.g. an area (in your example) with a texture (image) whereas the texture matches the area?

UEZ


Now I looked at your code (EDIT: from post #9) and I tried to run it.
I think you should use _GDIPlus_GraphicsFillEllipse() with constant X,Y coordinates to achieve your goal.
Maybe prepare memory bitmap with all drawn elipses and in main cycle just use BitBlt from this memory bitmap for each elipse.

Edited by Zedna, 07 December 2009 - 12:44 AM.


#14 UEZ

UEZ

    Never say never

  • MVPs
  • 3,605 posts

Posted 07 December 2009 - 12:22 AM

Now I looked at your code and I tried to run it.
I think you should use _GDIPlus_GraphicsFillEllipse() with constant X,Y coordinates to achieve your goal.
Maybe prepare memory bitmap with all drawn elipses and in main cycle just use BitBlt from this memory bitmap for each elipse.


You mean my example above: http://www.autoitscript.com/forum/index.php?showtopic=106021&view=findpost&p=751337 ?

I tried also _GDIPlus_TextureCreate() and assigned an image but the image will be static in the background. If you try to fill it with _GDIPlus_GraphicsFillEllipse() you will see within the moving ellipse the image partly (clipping of coordinate where the moving ellipse is).

UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#15 Authenticity

Authenticity

    Universalist

  • MVPs
  • 2,619 posts

Posted 07 December 2009 - 04:54 PM

I guess the the idea behind the texture and the hatch brushes is that the area behind it should be static. What you're asking is more like:

AutoIt         
;coded by UEZ 2009 #include <GUIConstantsEx.au3> #include <GDIP.au3> #include <WindowsConstants.au3> Global Const $width = @DesktopWidth / 2 Global Const $height = @DesktopHeight / 2 Opt("GUIOnEventMode", 1) Global $hwnd = GUICreate("Border Collision!", $width, $height, -1, -1, Default, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) GUISetOnEvent($GUI_EVENT_CLOSE, "close") GUISetState() _GDIPlus_Startup() Global $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd) Global $bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics) Global $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) _GDIPlus_GraphicsClear($backbuffer) _GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4) Global $max_dots = 20 Global $max_speed = 5 Global $iWidth = 60 Global $iHeight = 60 Dim $coordinates[$max_dots][5], $angle Dim $brush[$max_dots] Global $hImage[$max_dots] Global $hContext Global $hBrush Initialize() Do     _GDIPlus_GraphicsClear($backbuffer, 0xFF000000)     Draw_Dots()     Calculate_New_Position()     _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)     Sleep(30) Until False Func Initialize()     For $k = 0 To $max_dots - 1         $hImage[$k] = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)                 $hBrush = _GDIPlus_HatchBrushCreate(Random(0, 52, 1), 0xFF0000FF, 0xFFFFFFFF)         $hContext = _GDIPlus_ImageGetGraphicsContext($hImage[$k])         _GDIPlus_GraphicsFillEllipse($hContext, 0, 0, $iWidth, $iWidth, $hBrush)         _GDIPlus_GraphicsDispose($hContext)         _GDIPlus_BrushDispose($hBrush)         New_Coordinates($k)     Next EndFunc ;==>Initialize Func Draw_Dots()     Local $i, $temp_x, $temp_y     For $i = 0 To $max_dots - 1         _GDIPlus_GraphicsDrawImageRect($backbuffer, $hImage[$i], $coordinates[$i][0], $coordinates[$i][1], $iWidth, $iHeight)     Next EndFunc ;==>Draw_Dots Func New_Coordinates($k)     $coordinates[$k][0] = $width / 2 ;Random($width / 20, $width - $width / 20, 1);start x position     $coordinates[$k][1] = $height / 2 ;Random($height / 20, $height - $height / 20, 1) ;start y position     $coordinates[$k][2] = Random(1, $max_speed, 1) ;speed of pixel     $angle = Random(0, 359, 1) ;~ ConsoleWrite("Angle: " & $angle & "°" & @CRLF)     $coordinates[$k][3] = $coordinates[$k][2] * Cos($angle * 3.141592653 / 180)     $coordinates[$k][4] = $coordinates[$k][2] * Sin($angle * 3.141592653 / 180) EndFunc ;==>New_Coordinates Func Calculate_New_Position()     Local $k     For $k = 0 To $max_dots - 1         $coordinates[$k][0] += $coordinates[$k][3] ;increase x coordinate with appropriate slope         $coordinates[$k][1] += $coordinates[$k][4] ;increase y coordinate with appropriate slope         If $coordinates[$k][0] <= 0 Then ;border collision x left             $coordinates[$k][0] = 1             $coordinates[$k][3] *= -1         ElseIf $coordinates[$k][0] >= $width - $iWidth Then ;border collision x right             $coordinates[$k][0] = $width - ($iWidth + 1)             $coordinates[$k][3] *= -1         EndIf         If $coordinates[$k][1] <= 0 Then ;border collision y top             $coordinates[$k][1] = 1             $coordinates[$k][4] *= -1         ElseIf $coordinates[$k][1] >= $height - $iHeight Then ;border collision y bottom             $coordinates[$k][1] = $height - ($iHeight + 1)             $coordinates[$k][4] *= -1         EndIf     Next EndFunc ;==>Calculate_New_Position Func close()     For $k = 0 To $max_dots-1         _GDIPlus_ImageDispose($hImage[$k])     Next     _GDIPlus_BitmapDispose($bitmap)     _GDIPlus_GraphicsDispose($graphics)     _GDIPlus_GraphicsDispose($backbuffer)     _GDIPlus_Shutdown()     Exit EndFunc ;==>close  


#16 UEZ

UEZ

    Never say never

  • MVPs
  • 3,605 posts

Posted 07 December 2009 - 07:12 PM

I guess the the idea behind the texture and the hatch brushes is that the area behind it should be static. What you're asking is more like:


YES, exactly what I searched. I will try it also for the texture function! Well done!


How did you find the way?

Thanks,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#17 Authenticity

Authenticity

    Universalist

  • MVPs
  • 2,619 posts

Posted 07 December 2009 - 11:49 PM

While experimenting, but that was the first and only experiment anyway :)

I know think about adding the GDI+ v1.1 functions, mainly the effects and that, but it's not going to be part of the GDIPlus.au3 compliant, rather a different branch of GDIP.au3, call it GDIPlus11.au3 or something but I don't know. What you think? Example:

AutoIt         
#include <GDIPlus.au3> Global Const $GDIP_BLUREFFECT = "{633C80A4-1843-482b-9EF2-BE2834C5FDD4}" Global Const $GDIP_SHARPENEFFECT = "{63CBF3EE-C526-402c-8F71-62C540BF5142}" Global Const $GDIP_COLORMATRIXEFFECT = "{718F2615-7933-40e3-A511-5F68FE14DD74}" Global Const $GDIP_COLORLUTEFFECT = "{A7CE72A9-0F7F-40d7-B3CC-D0C02D5C3212}" Global Const $GDIP_BRIGHTNESSCONTRASTEFFECT = "{D3A1DBE1-8EC4-4c17-9F4C-EA97AD1C343D}" Global Const $GDIP_HUESATURATIONLIGHTNESSEFFECT = "{8B2DD6C3-EB07-4d87-A5F0-7108E26A9C5F}" Global Const $GDIP_LEVELSEFFECT = "{99C354EC-2A31-4f3a-8C34-17A803B33A25}" Global Const $GDIP_TINTEFFECT = "{1077AF00-2848-4441-9489-44AD4C2D7A2C}" Global Const $GDIP_COLORBALANCEEFFECT = "{537E597D-251E-48da-9664-29CA496B70F8}" Global Const $GDIP_REDEYECORRECTIONEFFECT = "{74D29D05-69A4-4266-9549-3CC52836B632}" Global Const $GDIP_COLORCURVEEFFECT = "{DD6A0022-58E4-4a67-9D9B-D48EB881A53D}" _GDIPlus11_Startup() If @error Then Exit MsgBox(0x10, "Error", "GDIPlus v1.1 is not installed") Local $hGUI, $hGraphics, $hImage, $hBlurredImage,  $hEffect $hGUI = GUICreate("", 640, 480) GUISetState() $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\flowers.jpg") $hEffect = _GDIPlus_EffectCreate($GDIP_BLUREFFECT) $hBlurredImage = _GDIPlus_BitmapCreateWithEffect($hImage, $hEffect) _GDIPlus_GraphicsDrawImage($hGraphics, $hBlurredImage, 0, 0) Do Until GUIGetMsg() = -3 _GDIPlus_BitmapDispose($hBlurredImage) _GDIPlus_EffectDispose($hEffect) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus11_Shutdown() Func _GDIPlus_BitmapApplyEffect($hBitmap, $hEffect, $pROI = 0)     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapApplyEffect", "hwnd", $hBitmap, "hwnd", $hEffect, "ptr", $pROI, "int", 0, "ptr*", 0, "int*", 0)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc Func _GDIPlus_BitmapCreateWithEffect($hBitmap, $hEffect, $pROI = 0, $pOutRect = 0)     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapCreateApplyEffect", "ptr*", $hBitmap, "int", 1, "hwnd", $hEffect, "ptr", $pROI, "ptr", $pOutRect, "int*", 0, "int", 0, "ptr*", 0, "int*", 0)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, $aResult[6]) EndFunc Func _GDIPlus_EffectCreate($sEffectGUID)     Local $iI, $tGUID, $pGUID, $tElem, $aElem[4], $aResult         $tGUID = _WinAPI_GUIDFromString($sEffectGUID)     $pGUID = DllStructGetPtr($tGUID)         $tElem = DllStructCreate("int[4]", $pGUID)     For $iI = 1 To 4         $aElem[$iI-1] = DllStructGetData($tElem, 1, $iI)     Next         $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateEffect", "int", $aElem[0], "int", $aElem[1], "int", $aElem[2], "int", $aElem[3], "int*", 0)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, $aResult[5]) EndFunc Func _GDIPlus_EffectDispose($hEffect)     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteEffect", "hwnd", $hEffect)         If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc Func _GDIPlus11_Startup()     Local $pInput, $tInput, $pToken, $tToken, $aResult     $giGDIPRef += 1     If $giGDIPRef > 1 Then Return True     $ghGDIPDll = DllOpen(@WindowsDir & "\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.6000.16386_none_8df21b8362744ace\gdiplus.dll")     _WinAPI_Check("_GDIPlus_Startup (GDIPlus.dll not found)", @error, False)     $tInput = DllStructCreate($tagGDIPSTARTUPINPUT)     $pInput = DllStructGetPtr($tInput)     $tToken = DllStructCreate("int Data")     $pToken = DllStructGetPtr($tToken)     DllStructSetData($tInput, "Version", 1)     $aResult = DllCall($ghGDIPDll, "int", "GdiplusStartup", "ptr", $pToken, "ptr", $pInput, "ptr", 0)     If @error Then Return SetError(@error, @extended, False)     $giGDIPToken = DllStructGetData($tToken, "Data")     Return $aResult[0] == 0 EndFunc Func _GDIPlus11_Shutdown()     If $ghGDIPDll = 0 Then Return SetError(-1, -1, False)     $giGDIPRef -= 1     If $giGDIPRef = 0 Then         DllCall($ghGDIPDll, "none", "GdiplusShutdown", "ptr", $giGDIPToken)         DllClose($ghGDIPDll)         $ghGDIPDll = 0     EndIf     Return True EndFunc


By the way, GDI+ v1.1 is distributed on Vista machines and up, so it's another problem.

#18 UEZ

UEZ

    Never say never

  • MVPs
  • 3,605 posts

Posted 08 December 2009 - 09:55 AM

The thing is to understand the functionality of all GDI+ functions. The names are not always clear to me what function is behind. Experimenting is probably the best way to check it out.

GDI+ v1.1 would be nice, too. It is possible to do some image manipulation.

Great job Authenticity!

Thanks,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#19 Authenticity

Authenticity

    Universalist

  • MVPs
  • 2,619 posts

Posted 08 December 2009 - 11:12 AM

The thing is to understand the functionality of all GDI+ functions. The names are not always clear to me what function is behind. Experimenting is probably the best way to check it out.
...


The functions naming is, as Paul Campbell did: The object the particular function applies comes first, followed by the verb and optionally the object or structure it's expecting. for example, GdipDrawEllipse is not relating to the graphics by it's name but it for sure exposed by the Graphics object so it becomes: _GDIPlus_GraphicsDrawRect. Another example is the GdipAddPathRectangle which becomes _GDIPlus_PathAddRectangle. Can you give an example of such function naming ambiguity? In any case I guess that the function's description is very helpful as MSDN can be ;)

Thanks UEZ.

#20 UEZ

UEZ

    Never say never

  • MVPs
  • 3,605 posts

Posted 08 December 2009 - 11:59 AM

Can you give an example of such function naming ambiguity? In any case I guess that the function's description is very helpful as MSDN can be ;)

Thanks UEZ.


I mean not ambiguity of function names but rather comprehensibility of function names. E.g. _GDIPlus_BitmapCreateFromScan0() (description: Creates a Bitmap object based on an array of bytes along with size and format information). This function was not intuitively understandable for me before you showed the example.
Also there are some more functions where I don't know what they are doing exactly. In that case I've to search e.g. at MSDN for a detailed decsription.

UEZ

Edited by UEZ, 08 December 2009 - 12:01 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users