Jump to content
Sign in to follow this  
gil900

Script crashes with _GDIPlus_Image ...

Recommended Posts

gil900

hello,

i have a test script that lists all the colors of each pixel in the some image.

this is the script:
 

#include <Array.au3>
#include <GDIPlus.au3>
_GDIPlus_Startup()

$ImageFile = @ScriptDir&"\1.bmp"
$AccuracyLevel = 10

ReturnArrayLetter($ImageFile,$AccuracyLevel)


Func ReturnArrayLetter($ImageFile,$AccuracyLevel)
    Local $Xsize , $Ysize , $hImage , $aOutput = ""
    $hImage = _GDIPlus_ImageLoadFromFile($ImageFile)
    $Xsize = _GDIPlus_ImageGetWidth($hImage)
    $Ysize = _GDIPlus_ImageGetHeight($hImage)
    ConsoleWrite("$Xsize = "&$Xsize&" , $Ysize = "&$Ysize&@CRLF)
    For $x = 1 To $Xsize
        For $y = 1 To $Ysize
            $PixelColor = _GDIPlus_BitmapGetPixel($hImage, $x, $y)
            ConsoleWrite($x&"x"&$y&": "&$PixelColor&@CRLF)
            ;Sleep(10)
        Next
    Next
    _GDIPlus_ImageDispose ($hImage)
    Return $aOutput
EndFunc


Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    Local $tArgb, $pArgb, $aRet , $Output = -1
    $tArgb = DllStructCreate("dword Argb")
    $pArgb = DllStructGetPtr($tArgb)
    $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)
    $Output = "0x"&Hex(DllStructGetData($tArgb, "Argb"), 6)
    _GDIPlus_ImageDispose($Output)
    Return $Output
EndFunc

the problem is that when i run this, i get this Error crash:

124a988.jpg

this is the full error:
 

 

Problem signature:
  Problem Event Name:    APPCRASH
  Application Name:    autoit3.exe
  Application Version:    3.3.8.1
  Application Timestamp:    4f25baec
  Fault Module Name:    kernel32.dll
  Fault Module Version:    6.1.7601.18015
  Fault Module Timestamp:    50b83c89
  Exception Code:    c0000005
  Exception Offset:    00011389
  OS Version:    6.1.7601.2.1.0.256.48
  Locale ID:    1037
  Additional Information 1:    0a9e
  Additional Information 2:    0a9e372d3b4ad19135b953a78882e789
  Additional Information 3:    0a9e
  Additional Information 4:    0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\System32\en-USerofflps.txt
 

 

i don't know why is this happening .. This should finish through all image ...

Please help me.
I I've attached a file that contains the script + image
:

problem.7z

thanks for helpers!

Share this post


Link to post
Share on other sites
gil900

thanks.

is there a AutoIt3Wrapper parameter for running the script with the beta version?

Share this post


Link to post
Share on other sites
Melba23

gil900,

Just press Alt-F5 to run a script with the Beta. Or add the following directive: :)

 

"#AutoIt3Wrapper_Version= ;(B/P) Use Beta or Production for AutoIt3 and Aut2Exe. Default is P"

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
gil900

gil900,

Just press Alt-F5 to run a script with the Beta. Or add the following directive: :)

 

"#AutoIt3Wrapper_Version= ;(B/P) Use Beta or Production for AutoIt3 and Aut2Exe. Default is P"

M23

 

thanks but this solution does not make my script work as  billo.

i don't get the error Double Function name...

 

Edited by gil900

Share this post


Link to post
Share on other sites
Melba23

gil900,

You do have the Beta installed? :huh:

M23

>Running AU3Check (3.3.9.22)  from:M:\Program\AutoIt3\Beta
"M:\Program\Au3 Scripts\fred1.au3"(29,49) : error: _GDIPlus_BitmapGetPixel() already defined.
Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
M:\Program\Au3 Scripts\fred1.au3 - 1 error(s), 0 warning(s)
!>20:32:48 AU3Check ended. Press F4 to jump to next error.rc:2
Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
guinness

Sometimes wonder why we bother maintaining a Helpfile. ;)

Same here.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
UEZ

Your function _GDIPlus_BitmapGetPixel() is not correct -> _GDIPlus_ImageDispose($Output) makes no sense (this cause the crash)!

Use this instead:

Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[4]
EndFunc   ;==>_GDIPlus_BitmapGetPixel

It will return an integer with the ARGB color value.

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

Share this post


Link to post
Share on other sites
gil900

Your function _GDIPlus_BitmapGetPixel() is not correct -> _GDIPlus_ImageDispose($Output) makes no sense (this cause the crash)!

Use this instead:

Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[4]
EndFunc   ;==>_GDIPlus_BitmapGetPixel

It will return an integer with the ARGB color value.

Br,

UEZ

Thank you!

This solution to the problem ..

I just found this function(_GDIPlus_BitmapGetPixel) and then I edited this function ..

I do not know what function _GDIPlus_ImageDispose() does.

Originally, this function was outside the _GDIPlus_BitmapGetPixel function and i thought it will look better and will work the same when it is in a function ..

It turns out I was wrong ..

Do you know what this function does?

I do not know why this function was included in the code.

It also works without this function ..

Share this post


Link to post
Share on other sites
UEZ

It releases the image handle (object). In your function you tried to release a pseudo image handle somewhere in the memory and that is the reason why you got the app crash (access violation)!

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

Share this post


Link to post
Share on other sites
gil900

Can you help me how to convert this variable:

$Image[$y][$x]

to a new $hImage variable?

this is how the $Image[$y][$x] variable will look:

    col 0       col 1       col 2      col 3       col4  ....

0x00000|0x00000|0x00000|0x00000 .....

0x00000|0x00000|0x00000|0x00000 .....

0x00000|0x00000|0x00000|0x00000 .....

0x00000|0x00000|0x00000|0x00000 .....

0x00000|0x00000|0x00000|0x00000 .....

.......

.......

i know how to create variable but i don't know how to convert it back to $hImage variable that supported by GDI+

Edited by gil900

Share this post


Link to post
Share on other sites
gil900

here is a picture from the variable:

1zmfqty.jpg

i need to convert it to image..

the goal is to work on the image through Array and then convert it to $hImage

Edited by gil900

Share this post


Link to post
Share on other sites
UEZ

Here a way (needs latest beta and untested):

 

$iH = UBound($Image) - 1
$iW = UBound($Image, 2) - 1
$hImage = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
For $y = 0 To $iH ;slower version
    For $x = 0 To $iW
        _GDIPlus_BitmapSetPixel($hImage, $x, $y, $Image[$y][$x])
    Next
Next

Edit: code corrected because _GDIPlus_BitmapSetPixel writes directly to the bitmap.

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

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  

×