Sign in to follow this  
Followers 0
Dieuz

Retrieve Pixel's color of a Picture file

5 posts in this topic

Hi there,

Let say I have a picture file named "image.gif" wich is 50x50 px in a folder.

How could I retrieve the color of each of these pixels and store them in an array?

Thanks!

;)

Share this post


Link to post
Share on other sites



I found this: http://www.autoitscript.com/forum/index.php?showtopic=100457&st=0&p=718522&hl=picture%20file%20pixel%20color&fromsearch=1&#entry718522

I will try it out!

Share this post


Link to post
Share on other sites

heres a quick and dirty 1D Array.

#include <GUIConstants.au3>
#Include <Array.au3>


splashimageon ("" , "watersmall.jpg" , 50 , 50 , 0 , 0 , 1)

Dim $Array[1]

$K = 1
For $B = 0 to 50
$color = pixelgetcolor ($B , $K)
;~ msgbox (0, '' , $color)
$Add = _ArrayAdd ($Array, $color)

If $K = 51 Then
    ExitLoop
    Endif

If $B = 50 Then
    $K = $K + 1
    $B = 0
    Endif

Next

_arraydelete($Array, 0)
_arraydelete($Array, $Add)
_arraydisplay($Array)


splashoff()

exit

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

Share this post


Link to post
Share on other sites

Try this.

Run script, and press left mouse button.

Press Esc to exit.

Drag any window over and off the desktop to act as an eraser.

#include <GUIConstants.au3>
#include <Array.au3>
#include <Misc.au3>

;======== load image into array ==============
SplashImageOn("", RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & _
        "\Examples\GUI\merlin.gif", 50, 50, 0, 0, 1)

Dim $Array[50][50]

For $B = 0 To UBound($Array, 1) - 1
    For $C = 0 To UBound($Array, 2) - 1
        $Array[$B][$C] = "0x" & Hex(PixelGetColor($B + 1, $C + 1), 6)
    Next
Next

_ArrayDisplay($Array)
SplashOff()

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

While 1
    Select
        Case _IsPressed("1B") ; Esc to exit
            ExitLoop
        Case _IsPressed("01") ; Left mouse button
            $aMPos = MouseGetPos()
            Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
            For $B = 0 To UBound($Array, 1) - 1
                For $C = 0 To UBound($Array, 2) - 1
                    DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $B + $aMPos[0], "long", $C + $aMPos[1], "long", _
                            "0x" & StringRegExpReplace(Hex($Array[$B][$C], 6), "(..)(..)(..)", "\3\2\1")) ; Change to 0xBBGGRR hex colour format.
                    ;_PixelSetColor($B + $aMPos[0], $C + $aMPos[1], $Array[$B][$C])
                Next
            Next
            DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $dc[0])
    EndSelect
WEnd

; 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

Share this post


Link to post
Share on other sites

Try this.

Run script, and press left mouse button.

Press Esc to exit.

Drag any window over and off the desktop to act as an eraser.

Heh great ;) i whas just browsing google out of boredom and stumbled onto this :)

I ended up making this with your example ;)http://imvu-products.biz/portrait.htm

Needs a few more tweaks shall post it when its done.

thanks

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