Jump to content

auto-paint program helpp!


laffo16
 Share

Recommended Posts

hi hi, i was thinking about making a program which would read a picture from paint brush, reading each pixel with pixelgetcolor, and then open a new pad and proceed to draw the image pixel by pixel as fast as it could. I just thought it would be cool to show my friends, and maybe later have all the pixel color/cords for a specific pic exported to a save file, so i could email it to a friend and they could watch the secret picture draw its self on their comp. ;)

well i soon enough ran into a problem with paint brush, i was wondering if someone might be able to help me here, i can retrieve the pixel color as RGB / BGR Hex or Dec, but i cant figure out how i can put these figures into paints custom colors tablet screen to get the correct colour. any help / advice appreciated man.

Link to comment
Share on other sites

I like this idea, I'm not the best here but this is how I would do it.

1. Set the area of the picture for pixelgetcolor (zx, zy ;; new coord)

2. Check each pixel and save their zx, zy coords and the color into a var

3. Set a point to start the draw at

4. Copy each pixel from their coords zx, zy

~Edit~ typo

Edited by newb_powa'
Link to comment
Share on other sites

it would be nice if you could post what you have so we can all take a look at it.

#Include <Misc.au3>

Global $k, $Pos, $x1, $y1, $x2, $y2, $startcoord, $endcoord

Func _setarea()
    For $k = 0 To 1
        While 1
            Sleep(100)
            $Pos = MouseGetPos()
            ToolTip("Press 'Spacebar' to set the top left corner of the area at mouse position", $Pos[0] + 5, $Pos[1] + 5)
            If _IsPressed(20) = 1 Then ExitLoop
        WEnd
        $startcoord = MouseGetPos()
        $k = 1
    Next
    For $k = 1 To 2
        While 1
            Sleep(100)
            $Pos = MouseGetPos()
            ToolTip("Press 'Spacebar' to set the bottom right corner of the area at mouse position", $Pos[0] + 5, $Pos[1] + 5)
            If _IsPressed(20) = 1 Then ExitLoop
        WEnd
        $endcoord = MouseGetPos()
        $k = 2
    Next
    $x1 = $startcoord[0]
    $y1 = $startcoord[1]
    $x2 = $endcoord[0]
    $y2 = $endcoord[1]
EndFuncoÝ÷ Ùg¥Øb²+ zÛbayÊ(­Ú¶­¬¢·î¶êî±â0Èb·lºÇºV®¶­sdvÆö&Âb33c¶²ÂÂb33c¶¢Âb33cµ÷2Âb33c¶7W'Âb33c¶7W'Âb33c·Âb33c·Âb33c·"Âb33c·"Âb33c·7F'F6ö÷&BÂb33c¶VæF6ö÷&BÂb33c¶æö2Âb33c¶ç"Âb33c´6öÆ÷  ¤gVæ2õVÆ6V6²b33c·Âb33c·Âb33c·"Âb33c·" b33c¶ç"Ò&÷VæBb33c·"Òb33c·²çVÖ&W"öbVÂâ&÷p b33c¶æö2Ò&÷VæBb33c·"Òb33c·²çVÖ&W"öb6öÇVÖç0  f÷"b33c¶¢ÒFòb33c¶ç  b33c¶7W'Òb33c·²b33c¶¢²7W'&VçBgV÷CµgV÷C° b33c¶7W'Òb33c·²7W'&VçBgV÷CµgV÷C° b33c´6öÆ÷"ÒVÄvWD6öÆ÷"b33c¶7W'Âb33c¶7W' æw&FRgV÷C´G&ræægV÷C²ÂgV÷CµDU5BgV÷C²ÂgV÷Cµ6ö÷&BgV÷C²fײb33c¶¢Âb33c¶7W' æw&FRgV÷C´G&ræægV÷C²ÂgV÷CµDU5BgV÷C²ÂgV÷Cµ6ö÷&BgV÷C²fײb33c¶¢Âb33c¶7W' æw&FRgV÷C´G&ræægV÷C²ÂgV÷CµDU5BgV÷C²ÂgV÷C²Ô4ôÄõ"ÒgV÷C²fײb33c¶¢Âb33c´6öÆ÷" æW@¤VæDgVæ0

This is my idea of the way to check pixel, I did not test it and it only work for one row, it should. I'm not going to try that tonight so I'll see that tomorow. I wish it help you to start.

Edited by newb_powa'
Link to comment
Share on other sites

its a bit slow going at the moment,

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

Global $paintname = "draw.jpg - Paint"

WinActivate($paintname)
WinWaitActive($paintname)
Sleep(500)
Send("^{PGDN}")
Sleep(500)

$ppos = WinGetPos($paintname)

Global $pix[156][131]

For $y = 0 to 130
    For $x = 0 to 155
        $pix[$x][$y] = Hex(PixelGetColor($ppos[0] + 65 + ($x * 4), $ppos[1] + 55 + ($y * 4)), 6)
    Next
Next

MouseClick("left", $ppos[0] + 15, $ppos[1] + 38, 1, 5)
Sleep(500)
MouseClick("left", $ppos[0] + 15, $ppos[1] + 57, 1, 5)
Sleep(500)
Send("^{PGDN}")
Sleep(500)

Global $px[4]
Dim $lastcolor = 0

For $y = 0 to 130
    For $x = 0 to 155
        
        If $lastcolor = $pix[$x][$y] And $x > 2 Then
            ; skip
            MouseClick("left", $ppos[0] + 65 + ($x * 4), $ppos[1] + 55 + ($y * 4), 1, 1)
        Else
            $lastcolor = $pix[$x][$y]
            
            $px[1] = Dec(StringLeft($pix[$x][$y], 2))
            $px[2] = Dec(StringMid($pix[$x][$y], 3, 2))
            $px[3] = Dec(StringRight($pix[$x][$y], 2))
            
            MouseClick("left", $ppos[0] + 250, $ppos[1] + $ppos[3] - 44, 2, 1)
            WinWaitActive("Edit Colors")
            $cpos = WinGetPos("Edit Colors")
            MouseClick("left", $cpos[0] + 30, $cpos[1] + 283, 1, 1)
            sleep(200)
            ControlSetText("Edit Colors", "", "Edit4", $px[1])
            ControlSetText("Edit Colors", "", "Edit5", $px[2])
            ControlSetText("Edit Colors", "", "Edit6", $px[3])
            ControlClick("Edit Colors", "", "Button2", "left", 1)
            MouseClick("left", $ppos[0] + 65 + ($x * 4), $ppos[1] + 55 + ($y * 4), 1, 1)
        EndIf
    Next
Next

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
    WEnd
EndFunc

Func Terminate()
    Exit 0
EndFunc
Link to comment
Share on other sites

thanks for your help tonight newb_powa', good sleep for you ^^. locomaestro do you mean as in setting the pixel color to paint with? if so i have attempted to solve that riddle in my script above.

i think now i'll try to paint all pixels of the same color in one go instead of repeated changing of colors.

Link to comment
Share on other sites

well, im done for the night. latest update...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.1.1.0
 Author:         laffo16

 Script Function:
    Auto Paint!

#ce ----------------------------------------------------------------------------

#include <Array.au3>

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

Global $paintname = "draw.bmp - Paint"

WinActivate($paintname)
WinWaitActive($paintname)
Sleep(500)
Send("^{PGDN}")
Sleep(500)

$ppos = WinGetPos($paintname)

Global $pix[156][131]

For $y = 0 to 130
    For $x = 0 to 155
        $pix[$x][$y] = Hex(PixelGetColor($ppos[0] + 65 + ($x * 4), $ppos[1] + 55 + ($y * 4)), 6)
    Next
Next

MouseClick("left", $ppos[0] + 15, $ppos[1] + 38, 1, 4)
Sleep(500)
MouseClick("left", $ppos[0] + 15, $ppos[1] + 57, 1, 4)
Sleep(500)
MouseClick("left", $ppos[0] + 19, $ppos[1] + 140, 1, 4)
Sleep(500)
Send("^{PGDN}")
Sleep(500)

Dim $px[4]
$sum = 130 * 155
Dim $colordump[$sum]
Dim $lastcolor = 0, $i = 0, $j = 0, $skip = 1

For $y = 0 to 130
    For $x = 0 to 155
        
        $skip = 1
        For $i = 0 to 40
            If $pix[$x][$y] = $colordump[$i] Then
                ;skip
                $skip = 2
            EndIf
        Next
        
        If $skip = 1 Then
            $px[1] = Dec(StringLeft($pix[$x][$y], 2))
            $px[2] = Dec(StringMid($pix[$x][$y], 3, 2))
            $px[3] = Dec(StringRight($pix[$x][$y], 2))
            MouseClick("left", $ppos[0] + 250, $ppos[1] + $ppos[3] - 44, 2, 1)
            Sleep(100)
            $cpos = WinGetPos("Edit Colors")
            MouseClick("left", $cpos[0] + 30, $cpos[1] + 283, 1, 1)
            Sleep(100)
            ControlSetText("Edit Colors", "", "Edit4", $px[1])
            ControlSetText("Edit Colors", "", "Edit5", $px[2])
            ControlSetText("Edit Colors", "", "Edit6", $px[3])
            ControlClick("Edit Colors", "", "Button2", "left", 1)
            MouseClick("left", $ppos[0] + 65 + ($x * 4), $ppos[1] + 55 + ($y * 4), 1, 1)
            
            For $y1 = 0 to 130
                For $x1 = 0 to 155
                    If $pix[$x1][$y1] = $pix[$x][$y] Then
                        If Hex(PixelGetColor($ppos[0] + 65 + ($x1 * 4), $ppos[1] + 55 + ($y1 * 4)), 6) = $pix[$x][$y] Then
                            ;skip
                        Else
                            MouseClick("left", $ppos[0] + 65 + ($x1 * 4), $ppos[1] + 55 + ($y1 * 4), 1, 1)
                        EndIf
                    EndIf
                Next
            Next
            $colordump[$j] = $pix[$x][$y]
            $j = $j + 1
        EndIf
        
    Next
Next

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
    WEnd
EndFunc

Func Terminate()
    Exit 0
EndFunc
Link to comment
Share on other sites

This function will save the color and the coords of each pixel in a .ini file. Now we only need something that can draw the picture pixel by pixel ^^

; By Newb Powa'
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯
#Include <Misc.au3>

Global $j, $h, $Pos, $curx, $cury, $x1, $y1, $x2, $y2, $startcoord, $endcoord, $noc, $npr, $Color

Func _Pixelcheck() ; This is the complete function
    
    _Setarea()  
    Sleep  (100)
    $npr = Round($x2 - $x1) ; Number of Pixel in a Row
    $nor = Round($y2 - $y1) ; Number Of Row
    $curx = $x1 ; X at start
    $cury = $y1 ; Y at start
    $j = 0 ; some var ;D
    $h = 0 ; some var ;D
    
    Do
        _Rowcheck()
        $j = 0 ; Reset $j to zero
        $cury = $cury-1 ; Do the _Rowcheck one row down
    Until $cury = $nor
    
EndFunc ; <== _Pixelcheck

Func _Setarea() ; This only set the coords for the _Pixelcheck func
    
        While 1
            Sleep(100)
            $Pos = MouseGetPos()
            $tooltipx = ToolTip("Press 'Spacebar' to set the top left corner of the area at mouse position", $Pos[0]+5, $Pos[1]+5)
            WinMove ($tooltipx, "", $Pos[0], $Pos[1])
            If _IsPressed(20) = 1 Then ExitLoop
        WEnd
        $startcoord = MouseGetPos()
        
        While 1
            Sleep(100)
            $Pos = MouseGetPos()
            $tooltipx = ToolTip("Press 'Spacebar' to set the bottom right corner of the area at mouse position", $Pos[0]+5, $Pos[1]+5)
            WinMove ($tooltipx, "", $Pos[0], $Pos[1])
            If _IsPressed(20) = 1 Then
                ToolTip( "", 0, 0)
                Sleep(500)
                ExitLoop
            EndIf  
        WEnd
        $endcoord = MouseGetPos()
          
    Sleep(100)
    $x1 = $startcoord[0]
    $y1 = $startcoord[1]
    $x2 = $endcoord[0]
    $y2 = $endcoord[1]
    Sleep(100)
    
EndFunc ; <== _Setarea

Func _Rowcheck() ; This get the pixel color of each pixel in a row
    For $j = 0 To $npr
        $h = $h+1
        $curx = $x1+$j ; Current "X"
        $cury = $cury ; Current "Y"
        $Color = PixelGetColor($curx, $cury)
        IniWrite("Draw.ini", "Color #" & $h, "X Coord ", $curx) ; Save the X coord of this pixel in a .ini file
        IniWrite("Draw.ini", "Color #" & $h, "Y Coord ", $cury) ; Save the Y coord of this pixel in a .ini file
        IniWrite("Draw.ini", "Color #" & $h, " Color  ", Hex($Color)) ;Save the color of this pixel in a .ini file
        IniWrite("Draw.ini", "Color #" & $h, "", "") ; Put a blank line in the .ini for easy read
    Next
EndFunc ; <== _Rowcheck

I'm not sure it's fully fonctionnal and it's pretty slow because there is a lot of stuff to do. Remember, an area of "30 pixels x 30 pixels" is 900 pixels to check ^^

I will try to improve it but I put it here now so it can give you some idea of how to continue with this stuff.

Newb Powa'

Link to comment
Share on other sites

Maybe I`m misunderstanding your purpose here, do you want to record the drawing as you do it?, could you not just record the mouse co-rds and clicks to draw the picture?

Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

This is an UDF I've made, makes it possible to set the color of pixels:

It should be noted that the pixel colors is not updated after they are drawn, meaning that if any other program redraws the window(updates it) the colors are restored to the original of the window.

Otherwise if it's just to draw in paint you could just do MouseClick()..

The _PixelSetColor set's one pixels color, the _DrawCrossHair draws a crosshair of specified size(note bigger $Size means slower)

Func _PixelSetColor($XCoord, $YCoord, $Color)
    
    Local $cHandle = DLLCall("user32.dll", "int", "GetDC", "hwnd", 0)
    
    If Not IsArray($cHandle) Then Return -1
    
    DllCall("gdi32.dll", "long", "SetPixel", "long", $cHandle[0], "long", $XCoord, "long", $YCoord, "long", $Color)
    
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $cHandle[0])
    
EndFunc

Func _DrawCrossHair($XCoord, $YCoord, $Color, $Size)
    
    _PixelSetColor($XCoord, $YCoord, $Color)
    
    If $Size > 0 Then
        For $i = 0 To $Size
            _PixelSetColor($XCoord, $YCoord, $Color)
            _PixelSetColor($XCoord-$i, $YCoord, $Color)
            _PixelSetColor($XCoord+$i, $YCoord, $Color)
            _PixelSetColor($XCoord, $YCoord-$i, $Color)
            _PixelSetColor($XCoord, $YCoord+$i, $Color)
        Next
    EndIf
    
EndFunc
Edited by FreeFry
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...