Sign in to follow this  
Followers 0
InunoTaishou

GDI+ Error description by code

1 post in this topic

#1 ·  Posted (edited)

Was getting some errors in my GDI+ project and wanted to know what they actually were, since I don't know what Error code 4 is.... So I looked it up on MSDN and put together a function that would give return a description of the error based on the code.

UDF:

; #FUNCTION# ====================================================================================================================
; Name...........:  _GDIPlus_GetErrorByCode
; Description....:  Get the error message for the @Extended error when a _GDIPlus_* function fails.
; Syntax.........:  _GDIPlus_GetErrorByCode ( [$iGDIError = @Extended [, Const $iReturnType = 0] ])
; Parameters.....:  $iGDIError   - The error to retrieve. Default is the last @Extended code.
;                   $iReturnType - What type the return should be. 0 will return a string, any other value returns an array.
;                                       - [0] Holds what type of error.
;                                       - [1] Holds the description.
; Return values..:  Success     - The error based on the code given in the formate requested.
;                   Failure     - The Error code given was out of range, not a valid code.
; Author.........:  InunoTaishou
; Remarks........:  Regardless of the error code a return in the format requested will be returned. If the code is out of range
;                   it will return an OutOfRange error.
; Related........:  GDIPlus
; Link...........:  https://msdn.microsoft.com/en-us/library/windows/desktop/ms534175%28v=vs.85%29.aspx
; Example........:  Yes
; ===============================================================================================================================
Func _GDIPlus_GetErrorByCode($iGDIError = @extended, Const $iReturnType = 0)
    Local Static $aErrors[22][2] = [["OK", "Indicates that the method call was successful."], _
            ["GenericError", "Indicates that there was an error on the method call, which is identified as something other than those defined by the other elements of this enumeration."], _
            ["InvalidParameter", "Indicates that one of the arguments passed to the method was not valid."], _
            ["OutOfMemory", "Indicates that the operating system is out of memory and could not allocate memory to process the method call. For an explanation of how constructors use the OutOfMemory status, see the Remarks section at the end of this topic."], _
            ["ObjectBusy", "Indicates that one of the arguments specified in the API call is already in use in another thread."], _
            ["InsufficientBuffer", "Indicates that a buffer specified as an argument in the API call is not large enough to hold the data to be received."], _
            ["NotImplemented", "Indicates that the method is not implemented."], _
            ["Win32Error", "Indicates that the method generated a Win32 error."], _
            ["WrongState", "Indicates that the object is in an invalid state to satisfy the API call. For example, calling Pen::GetColor from a pen that is not a single, solid color results in a WrongState status."], _
            ["Aborted", "Indicates that the method was aborted."], _
            ["FileNotFound", "Indicates that the specified image file or metafile cannot be found."], _
            ["ValueOverflow", "Indicates that the method performed an arithmetic operation that produced a numeric overflow."], _
            ["AccessDenied", "Indicates that a write operation is not allowed on the specified file."], _
            ["UnknownImageFormat", "Indicates that the specified image file format is not known."], _
            ["FontFamilyNotFound", "Indicates that the specified font family cannot be found. Either the font family name is incorrect or the font family is not installed."], _
            ["FontStyleNotFound", "Indicates that the specified style is not available for the specified font family."], _
            ["NotTrueTypeFont", "Indicates that the font retrieved from an HDC or LOGFONT is not a TrueType font and cannot be used with GDI+."], _
            ["UnsupportedGdiplusVersion", "Indicates that the version of GDI+ that is installed on the system is incompatible with the version with which the application was compiled."], _
            ["GdiplusNotInitialized", "Indicates that the GDI+API is not in an initialized state. To function, all GDI+ objects require that GDI+ be in an initialized state. Initialize GDI+ by calling GdiplusStartup."], _
            ["PropertyNotFound", "Indicates that the specified property does not exist in the image."], _
            ["PropertyNotSupported", "Indicates that the specified property is not supported by the format of the image and, therefore, cannot be set."], _
            ["ProfileNotFound", "Indicates that the color profile required to save an image in CMYK format was not found."]]
    Return (($iGDIError <= 21 And $iGDIError >= 0) ? _
            ($iReturnType = 0 ? $aErrors[$iGDIError][0] & ": " & $aErrors[$iGDIError][1] : StringSplit($aErrors[$iGDIError][0] & "|" & $aErrors[$iGDIError][1], "|", 2)) : _
            ($iReturnType = 0 ? SetError(10, 0, "OutOfRange: Error code " & $iGDIError & " is out of range") : SetError(10, $iGDIError, StringSplit("OutOfRange" & "|" & "Error code " & $iGDIError & " is out of range", "|", 2))))
EndFunc   ;==>_GDIPlus_GetErrorByCode

Example:

#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIEdit.au3>

_GDIPlus_Startup()
Global Const $GUI_EVENT_CLOSE = -3
Global $hGui = GUICreate("GDI+ Error by code", 800, 500)
Global $hEdit = _GUICtrlEdit_Create($hGui, "", 10, 300, 780, 190)
Global $hPic = GUICtrlGetHandle(GUICtrlCreatePic("", 0, 0, 800, 290))
Global $hDc = _WinAPI_GetWindowDC($hPic)
Global $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDc)
Global $hPen = _GDIPlus_PenCreate(0xFF00FFFF, 6)
Global $hFormat = _GDIPlus_StringFormatCreate()
Global $hFontFamily = _GDIPlus_FontFamilyCreate("Segoe UI")
Global $hFont = _GDIPlus_FontCreate($hFontFamily, 24)
Global $tLaytout = _GDIPlus_RectFCreate(0, 0, 800, 290)
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
Global $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Image1.jpg")
Global $hFile = FileOpen(@ScriptDir & "\Image2.jpg", 16 + 1)

_GDIPlus_StringFormatSetAlign($hFormat, 1)
_GDIPlus_StringFormatSetLineAlign($hFormat, 1)

GUISetState(@SW_SHOW, $hGui)

Debug("Error generating calls" & @CRLF)
Debug("Fake Font Family for _GDIPlus_FontFamilyCreate:" & _GDIPlus_FontFamilyCreate("AutoIt Rulez") & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("Wrong Parameter for _GDIPlus_GraphicsClear: " & _GDIPlus_GraphicsClear(0, 0xFFF0F0F0) & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("Load image for a file that's already open _GDIPlus_ImageLoadFromFile: " & _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Image2.jpg") & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("Save image over a file that's already open _GDIPlus_ImageSaveToFile: " & _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Image2.jpg") & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
_GDIPlus_ImageDispose($hImage)
Debug("Dispose image that's already been disposed _GDIPlus_ImageDispose: " & _GDIPlus_ImageDispose($hImage) & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)

Debug(@CRLF & "Non error generating calls" & @CRLF)
Debug("_GDIPlus_GraphicsClear: " & _GDIPlus_GraphicsClear($hGraphics, 0xFFF0F0F0) & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("_GDIPlus_GraphicsDrawStringEx: " & _
      _GDIPlus_GraphicsDrawStringEx($hGraphics, "This is a GDI+ UDF for getting the error message by @Extended code." & @CRLF & "Author: InunoTaishou", $hFont, $tLaytout, $hFormat, $hBrush) & _
      @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("_GDIPlus_GraphicsDrawRect: " & _GDIPlus_GraphicsDrawRect($hGraphics, 2, 2, 796, 286, $hPen) & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF & @CRLF)

Debug("All available errors:" & @CRLF & @TAB)
For $i = 0 to 21
    Debug($i & ": " & _GDIPlus_GetErrorByCode($i) & @CRLF & @TAB)
Next
_ArrayDisplay(_GDIPlus_GetErrorByCode(22, 1), "Error 22")

Do

Until (GUIGetMsg() = $GUI_EVENT_CLOSE)

_WinAPI_ReleaseDC($hPic, $hDc)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_PenDispose($hPen)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_FontFamilyDispose($hFontFamily)
_GDIPlus_BrushDispose($hBrush)
FileClose($hFile)
GUIDelete($hGui)
Exit 0

Func Debug(Const $sMsg = "")
    _GUICtrlEdit_AppendText($hEdit, $sMsg)
EndFunc   ;==>Debug

; #FUNCTION# ====================================================================================================================
; Name...........:  _GDIPlus_GetErrorByCode
; Description....:  Get the error message for the @Extended error when a _GDIPlus_* function fails.
; Syntax.........:  _GDIPlus_GetErrorByCode ( [$iGDIError = @Extended [, Const $iReturnType = 0] ])
; Parameters.....:  $iGDIError   - The error to retrieve. Default is the last @Extended code.
;                   $iReturnType - What type the return should be. 0 will return a string, any other value returns an array.
;                                       - [0] Holds what type of error.
;                                       - [1] Holds the description.
; Return values..:  Success     - The error based on the code given in the formate requested.
;                   Failure     - The Error code given was out of range, not a valid code.
; Author.........:  InunoTaishou
; Remarks........:  Regardless of the error code a return in the format requested will be returned. If the code is out of range
;                   it will return an OutOfRange error.
; Related........:  GDIPlus
; Link...........:  https://msdn.microsoft.com/en-us/library/windows/desktop/ms534175%28v=vs.85%29.aspx
; Example........:  Yes
; ===============================================================================================================================
Func _GDIPlus_GetErrorByCode($iGDIError = @extended, Const $iReturnType = 0)
    Local Static $aErrors[22][2] = [["OK", "Indicates that the method call was successful."], _
            ["GenericError", "Indicates that there was an error on the method call, which is identified as something other than those defined by the other elements of this enumeration."], _
            ["InvalidParameter", "Indicates that one of the arguments passed to the method was not valid."], _
            ["OutOfMemory", "Indicates that the operating system is out of memory and could not allocate memory to process the method call. For an explanation of how constructors use the OutOfMemory status, see the Remarks section at the end of this topic."], _
            ["ObjectBusy", "Indicates that one of the arguments specified in the API call is already in use in another thread."], _
            ["InsufficientBuffer", "Indicates that a buffer specified as an argument in the API call is not large enough to hold the data to be received."], _
            ["NotImplemented", "Indicates that the method is not implemented."], _
            ["Win32Error", "Indicates that the method generated a Win32 error."], _
            ["WrongState", "Indicates that the object is in an invalid state to satisfy the API call. For example, calling Pen::GetColor from a pen that is not a single, solid color results in a WrongState status."], _
            ["Aborted", "Indicates that the method was aborted."], _
            ["FileNotFound", "Indicates that the specified image file or metafile cannot be found."], _
            ["ValueOverflow", "Indicates that the method performed an arithmetic operation that produced a numeric overflow."], _
            ["AccessDenied", "Indicates that a write operation is not allowed on the specified file."], _
            ["UnknownImageFormat", "Indicates that the specified image file format is not known."], _
            ["FontFamilyNotFound", "Indicates that the specified font family cannot be found. Either the font family name is incorrect or the font family is not installed."], _
            ["FontStyleNotFound", "Indicates that the specified style is not available for the specified font family."], _
            ["NotTrueTypeFont", "Indicates that the font retrieved from an HDC or LOGFONT is not a TrueType font and cannot be used with GDI+."], _
            ["UnsupportedGdiplusVersion", "Indicates that the version of GDI+ that is installed on the system is incompatible with the version with which the application was compiled."], _
            ["GdiplusNotInitialized", "Indicates that the GDI+API is not in an initialized state. To function, all GDI+ objects require that GDI+ be in an initialized state. Initialize GDI+ by calling GdiplusStartup."], _
            ["PropertyNotFound", "Indicates that the specified property does not exist in the image."], _
            ["PropertyNotSupported", "Indicates that the specified property is not supported by the format of the image and, therefore, cannot be set."], _
            ["ProfileNotFound", "Indicates that the color profile required to save an image in CMYK format was not found."]]
    Return (($iGDIError <= 21 And $iGDIError >= 0) ? _
            ($iReturnType = 0 ? $aErrors[$iGDIError][0] & ": " & $aErrors[$iGDIError][1] : StringSplit($aErrors[$iGDIError][0] & "|" & $aErrors[$iGDIError][1], "|", 2)) : _
            ($iReturnType = 0 ? SetError(10, 0, "OutOfRange: Error code " & $iGDIError & " is out of range") : SetError(10, $iGDIError, StringSplit("OutOfRange" & "|" & "Error code " & $iGDIError & " is out of range", "|", 2))))
EndFunc   ;==>_GDIPlus_GetErrorByCode

 

Image1.jpg

Image2.jpg

Edited by InunoTaishou
Forgot to include the Images I used in the example.

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

  • Similar Content

    • argumentum
      By argumentum
      UDF to intercept the error window of AutoIt, showing more details about the error, including ability to save and send by email!
    • timmalos
      By timmalos
      Hey all.
      I'm trying to know when my user clicks on a Rect drawn via GDI+. Everything is almost working except I have a strange behaviour in the "order" clicks are fired.
      I created a simplified code to help :
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled _GDIPlus_Startup() Global $hGUI, $hGraphics Global $iWidth = 1024, $iHeight = 762 createGUI() draw() While 1 Sleep(10) WEnd Func createGUI() $hGUI = GUICreate("Current CasparCG Output", $iWidth,$iHeight) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetBkColor(0x000000) GUISetState(@SW_SHOW) $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) EndFunc ;==>Example Func draw() ;_WinAPI_draw($hGUI,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW)) _GDIPlus_GraphicsClear($hGraphics) $hFamily = _GDIPlus_FontFamilyCreate("Arial") $hFont = _GDIPlus_FontCreate($hFamily, 15, 1) $hPen = _GDIPlus_PenCreate(0xFFFEDCFF, 2) ;color format AARRGGBB (hex) $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) $hBrushString = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF00FF) ;color format AARRGGBB (hex) For $i = 1 to 2 Local $x = 0.25 Local $y = 0.25 Local $w = 0.5 Local $h = 0.5 Local $title = "Layer "&$i If $x >= -1 And $x <= 1 Then $x *= $iWidth If $y >= -1 And $y <= 1 Then $y *= $iHeight If $w >= -1 And $w <= 1 Then $w *= $iWidth If $h >= -1 And $h <= 1 Then $h *= $iHeight $hItem = GUICtrlCreateLabel("", $x,$y,$w,$h) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetOnEvent($hItem,"_gui_layer_clicked") ConsoleWrite("Created label with handle="&$hItem&" $i= " & $i&@CRLF) _GDIPlus_GraphicsFillRect($hGraphics, $x, $y, $w, $h,$hBrush) _GDIPlus_GraphicsDrawRect($hGraphics, $x, $y, $w, $h,$hPen) $tLayout = _GDIPlus_RectFCreate($x, $y, $w, $h) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $title, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphics, $title, $hFont, $aInfo[0], $hFormat, $hBrushString) Next _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_FontDispose($hFont) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_BrushDispose($hBrushString) Return 1 EndFunc Func _gui_layer_clicked() ConsoleWrite("Clicked on " & @GUI_CtrlId&@CRLF) EndFunc Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() Exit EndSelect EndFunc ;==>SpecialEvents What happens there :
      We have two rectangles, with the one labelled "2" is front and, the one labelled "1" in background. However when we click, the fired label is the one created first (in the background) and not the second one (in the front).
      Is it normal ?
      If yes, is there any way to change this order ? If I create another label after a first one on the same coords, I would the second one to be fired instead of the first one (This is a simplified code I can't just invert the label order creation easily)
       
      Thanks for your help
       
    • SkysLastChance
      By SkysLastChance
      I get this error, Whenever I try to find a date. Does anyone have any idea why? I saw some post from 2015, However I would imagine this is fixed by now. @water
      >"J:\Temporary Files\XXXXXXXXX\AutoIt\AutoIt\AutoIt\SciTe\..\autoit3.exe" /ErrorStdOut "C:\Users\XXXXXX\Desktop\Call Report Automation.au3"     "J:\Temporary Files\XXXXXXXX\AutoIt\AutoIt\AutoIt\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][1] = $oMatch^ ERROR >Exit code: 1    Time: 5.791 #include <Excel.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,Default,"A2",3) _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7") Sleep (1000) _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92") MsgBox (0,"Test",$oRead) UPDATE:
      If I take out this line it works. By works I mean I don't get the error. :/  However, I need it. I am just confused.
      _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7")  
      UPDATE 2: I also get this error when trying to use the helpfile examples. I have version 3.3.14.2
      \AutoIt\AutoIt\AutoIt\Include\Excel.au3" (670) : ==> The requested action with this object has failed.: $oSheet = $oWorkbook.Sheets($iIndexSheets) $oSheet = $oWorkbook^ ERROR >Exit code: 1 Time: 0.8931  
    • InunoTaishou
      By InunoTaishou
      Struggling a bit to get this GDI+ function converted to AutoIt.
      #include <GDIPlus.au3> _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile("F:\DCIM\Camera\20170515_111804.jpg") Global $tBufferSize = DllStructCreate("uint") Global $tProperties = DllStructCreate("uint") _GDIPlus_GetPropertySize($hImage, $tBufferSize, $tProperties) Global $tAllItems = DllStructCreate("struct;char[" & DllStructGetData($tBufferSize, 1) & "];endstruct") _GDIPlus_GetAllPropertyItems($hImage, $tBufferSize, $tProperties, $tPropertyItem) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Func _GDIPlus_GetAllPropertyItems(ByRef $hImage, Const $tTotalBufferSize, Const $tNumProperties, ByRef $tAllItems) If (Not IsDllStruct($tPropertyItem)) Then Return SetError(-1, 0, "") Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetAllPropertyItems", "hwnd", $hImage, "unit", DllStructGetData($tTotalBufferSize, 1), "uint", DllStructGetData($tNumProperties, 1), "ptr", DllStructGetPtr($tAllItems)) If (@error) Then Return SetError(@error, @extended, ConsoleWrite("@Error = " & @error & @LF)) If ($aResult[0]) Then Return SetError($aResult[0], @extended, "") Return $aResult[0] EndFunc ;==>_GDIPlus_GetAllPropertyItems Func _GDIPlus_GetPropertySize(Const ByRef $hImage, ByRef $tTotalBufferSize, ByRef $tNumProperties) If (Not IsDllStruct($tTotalBufferSize)) Then Return SetError(-1, 0, "") If (Not IsDllStruct($tNumProperties)) Then Return SetError(-2, 0, "") Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertySize", "hwnd", $hImage, "uint_ptr", DllStructGetPtr($tTotalBufferSize), "uint_ptr", DllStructGetPtr($tNumProperties)) If (@error) Then Return SetError(@error, @extended, "") If ($aResult[0]) Then Return SetError($aResult[0], 0, "") Return $aResult[0] EndFunc ;==>_GDIPlus_GetPropertySize Got the GetPropertySize function to work, gives me the correct buffer size and the property count, but I cannot figure out how to get the struct for the all items.
      Function on MSDN:
      https://msdn.microsoft.com/en-us/library/windows/desktop/ms535372(v=vs.85).aspx
      Struct needed:
      PropertyItem class:
      https://msdn.microsoft.com/en-us/library/windows/desktop/ms534493(v=vs.85).aspx
      Found other topics about this function in other languages where they used a blank string as the buffer, so I tried using a char array, which doesn't work. Just cannot figure out how to create the struct buffer to hold the data.
    • UEZ
      By UEZ
      Since I disovered FreeBasic I decided to create a DLL to implement much faster image processing functionality to AutoIt.
      Following functions are implemented yet:
      _GDIPlus_BitmapApplyFilter_BWJJNDithering _GDIPlus_BitmapApplyFilter_Cartoon1 _GDIPlus_BitmapApplyFilter_ColorAccent _GDIPlus_BitmapApplyFilter_Convolution_AnotherBlur _GDIPlus_BitmapApplyFilter_Convolution_BoxBlur _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection1 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection2 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection3 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection4 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection5 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection6 _GDIPlus_BitmapApplyFilter_Convolution_Emboss1 _GDIPlus_BitmapApplyFilter_Convolution_Emboss45Degree _GDIPlus_BitmapApplyFilter_Convolution_EmbossTopLeftBottomRight _GDIPlus_BitmapApplyFilter_Convolution_Gaussian3x3 _GDIPlus_BitmapApplyFilter_Convolution_Gaussian5x5_1 _GDIPlus_BitmapApplyFilter_Convolution_Gaussian5x5_2 _GDIPlus_BitmapApplyFilter_Convolution_GaussianBlur _GDIPlus_BitmapApplyFilter_Convolution_IntenseEmboss _GDIPlus_BitmapApplyFilter_Convolution_Kirsch _GDIPlus_BitmapApplyFilter_Convolution_Laplace1 _GDIPlus_BitmapApplyFilter_Convolution_Laplace2 _GDIPlus_BitmapApplyFilter_Convolution_Laplace3 _GDIPlus_BitmapApplyFilter_Convolution_LaplacianOfGaussian _GDIPlus_BitmapApplyFilter_Convolution_ManualMatrix _GDIPlus_BitmapApplyFilter_Convolution_MotionBlur _GDIPlus_BitmapApplyFilter_Convolution_Outline3x3 _GDIPlus_BitmapApplyFilter_Convolution_Prewitt _GDIPlus_BitmapApplyFilter_Convolution_Sharpen1 _GDIPlus_BitmapApplyFilter_Convolution_Sharpen2 _GDIPlus_BitmapApplyFilter_Convolution_Sobel _GDIPlus_BitmapApplyFilter_Convolution_SovelVsPrewitt _GDIPlus_BitmapApplyFilter_Convolution_TriangleBlur _GDIPlus_BitmapApplyFilter_Convolution_Unsharp _GDIPlus_BitmapApplyFilter_Convolution_Unsharp5x5 _GDIPlus_BitmapApplyFilter_Dilatation _GDIPlus_BitmapApplyFilter_DistortionBlur _GDIPlus_BitmapApplyFilter_Edges _GDIPlus_BitmapApplyFilter_Erosion _GDIPlus_BitmapApplyFilter_FishEye _GDIPlus_BitmapApplyFilter_Indexed _GDIPlus_BitmapApplyFilter_Jitter _GDIPlus_BitmapApplyFilter_Kuwahara _GDIPlus_BitmapApplyFilter_Linellism _GDIPlus_BitmapApplyFilter_Median _GDIPlus_BitmapApplyFilter_Median2 _GDIPlus_BitmapApplyFilter_OilPainting _GDIPlus_BitmapApplyFilter_PenSketch _GDIPlus_BitmapApplyFilter_PenSketch2 _GDIPlus_BitmapApplyFilter_Pixelate _GDIPlus_BitmapApplyFilter_Pointillism _GDIPlus_BitmapApplyFilter_RadialBlur _GDIPlus_BitmapApplyFilter_Raster _GDIPlus_BitmapApplyFilter_Swirl _GDIPlus_BitmapApplyFilter_SymmetricNearestNeighbour _GDIPlus_BitmapApplyFilter_TiltShift _GDIPlus_BitmapApplyFilter_TimeWarp _GDIPlus_BitmapApplyFilter_Wave _GDIPlus_BitmapApplyFilter_XRay  
      Since I am absolutely a newbie in FreeBasic, the DLL may contain errors.  Please report any bug.
       
      FreeBasic source code can be found here: https://pastebin.com/Lugp6rCR
       
      To do:
      add function headers with descriptions speed-up FB code -> partly done add more filters -> ongoing  
      Credits to:
      Jakub Szymanowski rdc Dewald Esterhuizen Santhosh G_  Christian Graus www.gutgames.com  
      Have fun.
       
      Download link: 
       
      You can compare the speed with AutoIt version:
      #AutoIt3Wrapper_Version=b #include <Array.au3> #include <GDIPlus.au3> Global $sFile = FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.gif;*.bmp)") If @error Then Exit _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global Const $hImage = _GDIPlus_ImageLoadFromFile($sFile) Global Const $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Global Const $hGUI = GUICreate("GDI+ Image Filters", $iW * 2, $iH) Global $fProg = 0, $iEnd = $iW * $iH - 1 AdlibRegister("Progress", 490) Global $t = TimerInit() Global Const $hGDIBitmap = _GDIPlus_BitmapApplyFilter_Median($hImage, 4) ConsoleWrite(Round(TimerDiff($t) / 1000, 2) & " s / " & Round(TimerDiff($t) / 60000, 2) & " min" & @CRLF) Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW - 1, $iH - 1) Global Const $iPic_o = GUICtrlCreatePic("", $iW, 0, $iW - 1, $iH - 1) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBitmap)) Global Const $hGDIBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic_o, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBitmap2)) GUISetState() AdlibUnRegister("Progress") ToolTip("") Do Until GUIGetMsg() = -3 _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hGDIBitmap) _WinAPI_DeleteObject($hGDIBitmap2) _GDIPlus_Shutdown() Exit Func Progress() ToolTip(Int($fProg / $iEnd * 100) & " % / " & Round(TimerDiff($t) / 60000, 2) & " min", MouseGetPos(0) + 30, MouseGetPos(1) + 30) EndFunc #Region Symmetric Nearest Neighbour Func _GDIPlus_BitmapApplyFilter_SymmetricNearestNeighbour($hImage, $fRadius = 2, $bGDI = True) ;no alpha channel implemented yet Local Const $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Local Const $hBitmap_Dest = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $tBitmapData_Dest = _GDIPlus_BitmapLockBits($hBitmap_Dest, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMWRITE, $GDIP_PXF32ARGB) Local Const $iScan0_Dest = DllStructGetData($tBitmapData_Dest, "Scan0") Local Const $tPixel_Dest = DllStructCreate("int[" & $iW * $iH & "];", $iScan0_Dest) Local Const $tBitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMREAD, $GDIP_PXF32ARGB) Local Const $iScan0 = DllStructGetData($tBitmapData, "Scan0") Local Const $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0) Local $iRowOffset, $iX, $iY, $c, $k, $sumR, $sumG, $sumB, $iCount, $xx, $yy, $iR, $iG, $iB, $iR1, $iG1, $iB1, $iR2, $iG2, $iB2, $x, $y For $iY = 0 To $iH - 1 $iRowOffset = $iY * $iW For $iX = 0 To $iW - 1 $sumR = 0 $sumG = 0 $sumB = 0 $iCount = 0 $c = DllStructGetData($tPixel, 1, $iRowOffset + $iX) $iR = BitShift(BitAND(0x00FF0000, $c), 16) $iG = BitShift(BitAND(0x0000FF00, $c), 8) $iB = BitAND(0x000000FF, $c) For $yy = -$fRadius To $fRadius For $xx = -$fRadius To $fRadius $k = $iX + $xx $x = $k < 0 ? 0 : $k > $iW - 1 ? $iW - 1 : $k $k = $iY + $yy $y = $k < 0 ? 0 : $k > $iH - 1 ? $iH - 1 : $k $c = DllStructGetData($tPixel, 1, $y * $iW + $x) $iR1 = BitShift(BitAND(0x00FF0000, $c), 16) $iG1 = BitShift(BitAND(0x0000FF00, $c), 8) $iB1 = BitAND(0x000000FF, $c) $k = $iX - $xx $x = $k < 0 ? 0 : $k > $iW - 1 ? $iW - 1 : $k $k = ($iY - $yy) $y = $k < 0 ? 0 : $k > $iH - 1 ? $iH - 1 : $k $c = DllStructGetData($tPixel, 1, $y * $iW + $x) $iR2 = BitShift(BitAND(0x00FF0000, $c), 16) $iG2 = BitShift(BitAND(0x0000FF00, $c), 8) $iB2 = BitAND(0x000000FF, $c) If __DeltaE($iR, $iG, $iB, $iR1, $iG1, $iB1) < __DeltaE($iR, $iG, $iB, $iR2, $iG2, $iB2) Then $sumR += $iR1 $sumG += $iG1 $sumB += $iB1 Else $sumR += $iR2 $sumG += $iG2 $sumB += $iB2 EndIf $iCount += 1 Next Next DllStructSetData($tPixel_Dest, 1, 0xFF000000 + Int($sumR / $iCount) * 0x10000 + Int($sumG / $iCount) * 0x100 + Int($sumB / $iCount), $iRowOffset + $iX) $fProg += 1 Next Next _GDIPlus_BitmapUnlockBits($hImage, $tBitmapData) _GDIPlus_BitmapUnlockBits($hBitmap_Dest, $tBitmapData_Dest) _GDIPlus_ImageSaveToFile($hBitmap_Dest, @ScriptDir & "\Filter_SNN" & $fRadius & "_" & @YEAR & @MON & @MDAY & @MIN & @SEC & ".png") If $bGDI Then Local $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Dest) _GDIPlus_BitmapDispose($hBitmap_Dest) Return $hGDIBitmap EndIf Return $hBitmap_Dest EndFunc Func __DeltaE($iR1, $iG1, $iB1, $iR2, $iG2, $iB2) Return Sqrt(($iR1 - $iR2) * ($iR1 - $iR2) + ($iG1 - $iG2) * ($iG1 - $iG2) + ($iB1 - $iB2) * ($iB1 - $iB2)) EndFunc #EndRegion #Region Jitter Func _GDIPlus_BitmapApplyFilter_Jitter($hImage, $iAmount = 20, $bGDI = True) Local Const $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Local Const $hBitmap_Dest = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $tBitmapData_Dest = _GDIPlus_BitmapLockBits($hBitmap_Dest, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMWRITE, $GDIP_PXF32ARGB) Local Const $iScan0_Dest = DllStructGetData($tBitmapData_Dest, "Scan0") Local Const $tPixel_Dest = DllStructCreate("int[" & $iW * $iH & "];", $iScan0_Dest) Local Const $tBitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMREAD, $GDIP_PXF32ARGB) Local Const $iScan0 = DllStructGetData($tBitmapData, "Scan0") Local Const $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0) Local $iX, $iY, $iRowOffset, $fNX, $fNY For $iY = 0 To $iH - 1 $iRowOffset = $iY * $iW + 1 For $iX = 0 To $iW - 1 $fNX = $iX + Int((Random() - 0.5) * $iAmount) $fNX = $fNX < 1 ? 1 : $fNX > $iW - 1 ? $iW - 1 : $fNX $fNY = ($iY + Int((Random() - 0.5) * $iAmount)) $fNY = $fNY < 1 ? 1 : $fNY > $iH - 1 ? $iH - 1 : $fNY $fNY *= $iW DllStructSetData($tPixel_Dest, 1, DllStructGetData($tPixel, 1, $fNY + $fNX), $iRowOffset + $iX) $fProg += 1 Next Next _GDIPlus_BitmapUnlockBits($hImage, $tBitmapData) _GDIPlus_BitmapUnlockBits($hBitmap_Dest, $tBitmapData_Dest) _GDIPlus_ImageSaveToFile($hBitmap_Dest, @ScriptDir & "\Filter_Jitter" & $iAmount & "_" & @YEAR & @MON & @MDAY & @MIN & @SEC & ".png") If $bGDI Then Local $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Dest) _GDIPlus_BitmapDispose($hBitmap_Dest) Return $hGDIBitmap EndIf Return $hBitmap_Dest EndFunc #EndRegion #Region Median Func _GDIPlus_BitmapApplyFilter_Median($hImage, $fRadius = 3, $bGDI = True) Local Const $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Local Const $hBitmap_Dest = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $tBitmapData_Dest = _GDIPlus_BitmapLockBits($hBitmap_Dest, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMWRITE, $GDIP_PXF32ARGB) Local Const $iScan0_Dest = DllStructGetData($tBitmapData_Dest, "Scan0") Local Const $tPixel_Dest = DllStructCreate("int[" & $iW * $iH & "];", $iScan0_Dest) Local Const $tBitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMREAD, $GDIP_PXF32ARGB) Local Const $iScan0 = DllStructGetData($tBitmapData, "Scan0") Local Const $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0) Local $iX, $iY, $iRowOffset For $iY = 0 To $iH - 1 $iRowOffset = $iY * $iW + 1 For $iX = 0 To $iW - 1 DllStructSetData($tPixel_Dest, 1, __Median_Value($iX, $iY, $fRadius, $tPixel, $iW, $iH), $iRowOffset + $iX) $fProg += 1 Next Next _GDIPlus_BitmapUnlockBits($hImage, $tBitmapData) _GDIPlus_BitmapUnlockBits($hBitmap_Dest, $tBitmapData_Dest) _GDIPlus_ImageSaveToFile($hBitmap_Dest, @ScriptDir & "\Filter_Median" & $fRadius & "_" & @YEAR & @MON & @MDAY & @MIN & @SEC & ".png") If $bGDI Then Local $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Dest) _GDIPlus_BitmapDispose($hBitmap_Dest) Return $hGDIBitmap EndIf Return $hBitmap_Dest EndFunc Func __Median_Value($iPosX, $iPosY, $fRadius, $tPixel, $iW, $iH) Local $iX, $iY, $aColors[1000], $iColors = 0, $iSize = $iW * $iH - 1, $iOff, $e For $iX = $iPosX - $fRadius To $iPosX + $fRadius For $iY = $iPosY - $fRadius To $iPosY + $fRadius $iOff = 1 + $iY * $iW + $iX $aColors[$iColors] = DllStructGetData($tPixel, 1, $iOff < 1 ? 1 : $iOff > $iSize ? $iSize : $iOff) $iColors += 1 Next Next ReDim $aColors[$iColors] ;~ _ArraySort($aColors, 0) $e = $iColors - 1 __ArrayQuickSort1D($aColors, 0, $e) Local $iMid = Floor($iColors / 2), $iMedian If BitAND($iColors, 1) Then $iMedian = Int($aColors[$iMid + 1]) Else $iMedian = Int(($aColors[$iMid] + $aColors[$iMid + 1]) / 2) EndIf Return $iMedian EndFunc #EndRegion