Sign in to follow this  
Followers 0
iamtheky

Picture --> Array -->File and back

1 post in this topic

#1 ·  Posted (edited)

in my use i am loading icons to arrays from text files and splashing them in all fun like.

There is about a 15 second lag time per 90x90 array during the _load() function.

Demo:

#include <Array.au3>
Dim $BArray[90][90]

$merlin = _PicToArray(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\merlin.gif")

_save($merlin , "C:\test\merlin.txt")

$oobe = _PicToArray(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\msoobe.jpg")

_save($oobe , "C:\test\oobe.txt")

$fromFile1 = _load("c:\test\merlin.txt" , $BArray)

$fromFile2 = _load("c:\test\oobe.txt" , $BArray)

Dim $ZArray[8100][3]
$k = 0
For $i = 0 To 89
    For $j = 0 To 89
        $ZArray[$k][0] = Random(0,10000,1)
        $ZArray[$k][1] = $i
        $ZArray[$k][2] = $j
        $k+=1
    Next
Next
_ArraySort($ZArray)


_DrawPicfromArray ($fromfile1, '15000')

_DrawPicfromArray ($fromfile2, '15000')


Func _PicToArray($pic)
SplashImageOn("", $pic , 90, 90, 0, 0, 1)
For $B = 0 To UBound($BArray, 1) - 1
    For $C = 0 To UBound($BArray, 2) - 1
        $BArray[$B][$C] = "0x" & Hex(PixelGetColor($B + 1, $C + 1), 6)
    Next
Next
splashoff ()
Return $BArray
EndFunc


Func _save($SrcArray , $file)
$save = fileopen ($file , 10)
for $K = 0 to Ubound($SrcArray, 1) - 1
For $L = 0 To UBound($SrcArray, 2) - 1
filewrite ($save, $SrcArray[$K][$L] & @CRLF)
Next
Next
FileClose ($save)
EndFunc

Func _DrawPicfromArray($Srcarray, $TimerARG)
;========= Draw array of pixels to desktop at mouse button down ===============
Local $aMPos, $dc

$start1 = TimerInit ()
$dif = timerdiff($start1)

While 1
    If timerdiff($start1) >= $TimerARG Then
        ExitLoop
        Endif
  Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    Local $D, $E
    For $i = 0 To 8099
        $D = $ZArray[$i][1]
        $E = $ZArray[$i][2]
        _PixelSetColor($D, $E, $Srcarray[$D][$E])
        _HPSleep(100,0)
    Next
  DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $dc[0])
WEnd
EndFunc

; Modified from http://www.autoitscript.com/forum/index.php?showtopic=7315&view=findpost&p=178779
Func _PixelSetColor($XCoord, $YCoord, $Color)
    Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    If Not IsArray($dc) Then Return -1
    DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $XCoord, "long", $YCoord, "long", _
            "0x" & StringRegExpReplace(hex($Color,6), "(..)(..)(..)", "\3\2\1")) ; Change to 0xBBGGRR hex colour format.
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $dc[0])
EndFunc ;==>_PixelSetColor

Func _HPSleep($iSleep, $fMs = 1)
    ; default is milliseconds, otherwise microseconds (1 ms = 1000 µs)
    If $fMs Then $iSleep *= 1000 ; convert to ms
    DllCall("ntdll.dll", "dword", "NtDelayExecution", "int", 0, "int64*", -10 * $iSleep)
EndFunc


Func _load($file, $DestArray)
$file = fileopen ($file , 0)
$J = Ubound($Destarray, 1) - 1
$l = 1
for $K = 0 to $J
for $i = 0 to $J
$line = filereadline ($file , $l)
$Destarray[$K][$i] = $line
$l += 1
Next
Next
FileClose ($file)
Return $DestArray
EndFunc

Split into Save section and Load section

SAVE:

#include <Array.au3>
Dim $BArray[90][90]

$merlin = _PicToArray(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\merlin.gif")

_save($merlin , "C:\test\merlin.txt")

$oobe = _PicToArray(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\msoobe.jpg")

_save($oobe , "C:\test\oobe.txt")

Func _PicToArray($pic)
SplashImageOn("", $pic , 90, 90, 0, 0, 1)
For $B = 0 To UBound($BArray, 1) - 1
    For $C = 0 To UBound($BArray, 2) - 1
        $BArray[$B][$C] = "0x" & Hex(PixelGetColor($B + 1, $C + 1), 6)
    Next
Next
splashoff ()
Return $BArray
EndFunc


Func _save($SrcArray , $file)
$save = fileopen ($file , 10)
for $K = 0 to Ubound($SrcArray, 1) - 1
For $L = 0 To UBound($SrcArray, 2) - 1
filewrite ($save, $SrcArray[$K][$L] & @CRLF)
Next
Next
FileClose ($save)
EndFunc

LOAD:

#include <Array.au3>
Dim $BArray[90][90]

$merlin = _load("c:\test\merlin.txt" , $BArray)


_DrawPicfromArray ($merlin)






Func _DrawPicfromArray($Srcarray)

Dim $ZArray[8100][3]
$k = 0
For $i = 0 To 89
    For $j = 0 To 89
        $ZArray[$k][0] = Random(0,10000,1)
        $ZArray[$k][1] = $i
        $ZArray[$k][2] = $j
        $k+=1
    Next
Next
_ArraySort($ZArray)

;========= Draw array of pixels to desktop at mouse button down ===============
Local $aMPos, $dc

$start1 = TimerInit ()
$dif = timerdiff($start1)

While timerdiff($start1) < 15000
  Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    Local $D, $E
    For $i = 0 To 8099
        $D = $ZArray[$i][1]
        $E = $ZArray[$i][2]
        _PixelSetColor($D, $E, $Srcarray[$D][$E])
        _HPSleep(100,0)
    Next
  DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $dc[0])
WEnd


EndFunc

; Modified from http://www.autoitscript.com/forum/index.php?showtopic=7315&view=findpost&p=178779
Func _PixelSetColor($XCoord, $YCoord, $Color)
    Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    If Not IsArray($dc) Then Return -1
    DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $XCoord, "long", $YCoord, "long", _
            "0x" & StringRegExpReplace(hex($Color,6), "(..)(..)(..)", "\3\2\1")) ; Change to 0xBBGGRR hex colour format.
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $dc[0])
EndFunc ;==>_PixelSetColor

Func _HPSleep($iSleep, $fMs = 1)
    ; default is milliseconds, otherwise microseconds (1 ms = 1000 µs)
    If $fMs Then $iSleep *= 1000 ; convert to ms
    DllCall("ntdll.dll", "dword", "NtDelayExecution", "int", 0, "int64*", -10 * $iSleep)
EndFunc


Func _load($file, $DestArray)
$file = fileopen ($file , 0)
$J = Ubound($Destarray, 1) - 1
$l = 1
for $K = 0 to $J
for $i = 0 to $J
$line = filereadline ($file , $l)
$Destarray[$K][$i] = $line
$l += 1
Next
Next
FileClose ($file)
Return $DestArray
EndFunc

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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