Jump to content
Sign in to follow this  
polaski

Array Mirror and flip.

Recommended Posts

polaski

I`ve got little problem with my drawing script.

When detonating that script in paint it just draw a BMP array but flipped by 90 degrees and "mirror image".

I was testing it in winXP mspaint. In other systems just place MouseMove it in diffrent place. 150pix x 150 pix Black&White BMP.

Can some one just rebuild my arrays to get normal image?

MouseMove(105,76,1) in other place.

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

 AutoIt Version: 3.3.14.0
 Author:         polaski Marcin PRzyborowski

 Script Function: Convert BMP image into Array[x,y]=[Hex colour]
https://www.autoitscript.com/forum/topic/112540-is-there-a-function-for-reading-images-into-2d-arrays/?do=findComment&comment=788472
https://www.autoitscript.com/forum/topic/27362-bitmap-library/
script create an 2d Matrix.

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


#include <BMP3.au3> ;https://www.autoitscript.com/forum/topic/27362-bitmap-library/
#include <Array.au3>
#include <File.au3>

;;;;;;;;;;;;;;;;;hotkeye;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Press Esc to terminate script, Pause/Break to "pause"

Global $g_bPaused = False

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

;While 1
;    Sleep(100)
;WEnd

Func TogglePause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit
EndFunc   ;==>Terminate



;;;;;;;;;;;;;;;;;hotkey end;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Global $Paused


Local $filename = FileOpenDialog("Select image", @DesktopCommonDir, "All images (*.jpg;*.png;*.gif;*.bmp;)", 1)

$bmp = _BMPOpen($filename,1) ;zwraca uchwyt do bitmapy która otworzylismy.


Dim $tab3d[$bmp[1]][$bmp[2]] ;tablica o wymiarach bitmapy

;;;pętla zbierająca pixele;;;;
For $j = 0 To $bmp[1] - 1
        For $i = 0 To $bmp[2] - 1
           $tab3d[$j][$i]=_PixelRead($bmp,$j,$i)
         Next
      Next



      ;hójowa tablica 6 na 6
Global $glebokosc = 0
Global $kolor = 0
Global $pamiec = 0
Global $w1


call(start)
call (czytaj)


func start()


 If WinExists("[CLASS:MSPaintApp]") Then
      WinKill("[CLASS:MSPaintApp]", "")
        ;WinKill("Kolko i Krzyzyk")
     EndIf

Run("mspaint.exe")

$hWnd =  WinWait("[CLASS:MSPaintApp]", "",2)
sleep(2000)
 WinMove("[CLASS:MSPaintApp]",  "", 0, 0, 1000, 1000)

Sleep(10000)

MouseMove(105,76,1)

EndFunc




func czytaj()
For $j = 0 to $bmp[1] - 1
   $w1=MouseGetPos()
        For $i = 0 To $bmp[2] - 1


$pamiec=$glebokosc
;$kolor=$tab3d[$j][$i]

if $tab3d[$j][$i]='000000' Then
   call(wierc)

while $i < $bmp[2]-1 And $tab3d[$j][$i]=$tab3d[$j][$i+1]
$i=$i+1
;if $i=$bmp[2] then ExitLoop
;if $i=$bmp[2]-1 then ExitLoop

;_ArrayDisplay ($tab3d)
MouseDown ( "left" )
call(posowaj)
WEnd
MouseUP ("left")


   call(wyciagaj)
   call(posowaj)
   EndIf


if $tab3d[$j][$i]='FFFFFF' Then
   call(posowaj)
EndIf


Next
call(wroc)
Next

EndFunc

Func wierc()
Local $w2=mousegetpos()
MouseClick ("left", $w2[0],$w2[1]  , 1 ,  1 )
;beep(300,300)
EndFunc


Func wyciagaj()
Local $w2=mousegetpos()
;MouseClick ("right", $w2[0],$w2[1]  , 1 ,  1 )
;beep(800,300)
EndFunc

Func posowaj()
Local $w2=mousegetpos()
MouseMove ($w2[0]+2,$w2[1] , 0 )

EndFunc


func wroc()
    MouseMove ( $w1[0],$w1[1]+2  , 0 )
EndFunc

 

 

 

Edited by polaski

Share this post


Link to post
Share on other sites
polaski

Now Declared. It should Pause now.

I added image that worsk with that script.

imagemirror.bmp

Edited by polaski

Share this post


Link to post
Share on other sites
LarsJ

Try this code:

#include <BMP3.au3> ;https://www.autoitscript.com/forum/topic/27362-bitmap-library/
#include <Array.au3>
#include <File.au3>

Global $g_bPaused = False

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

Func TogglePause()
  $g_bPaused = Not $g_bPaused
  While $g_bPaused
    Sleep(100)
    ToolTip('Script is "Paused"', 0, 0)
  WEnd
  ToolTip("")
EndFunc

Func Terminate()
    Exit
EndFunc

Local $filename = FileOpenDialog("Select image", @DesktopCommonDir, "All images (*.jpg;*.png;*.gif;*.bmp;)", 1)
$bmp = _BMPOpen($filename,1) ;zwraca uchwyt do bitmapy która otworzylismy.

Dim $tab3d[$bmp[2]][$bmp[1]]

For $i = 0 To $bmp[1] - 1
  For $j = 0 To $bmp[2] - 1
    $tab3d[$j][$i]=_PixelRead($bmp,$i,$j)
  Next
Next

If WinExists("[CLASS:MSPaintApp]") Then _
  WinKill("[CLASS:MSPaintApp]", "")
Run("mspaint.exe")
$hWnd =  WinWait("[CLASS:MSPaintApp]", "",2)
sleep(200)
WinMove("[CLASS:MSPaintApp]",  "", 0, 0, 1000, 1000)
Sleep(200)
MouseMove(105,76,1)
  
Local $w1, $w2
For $i = 0 to $bmp[2] - 1
  $w1=MouseGetPos()
  For $j = 0 To $bmp[1] - 1
    if $tab3d[$i][$j]='000000' Then
      Local $w2=MouseGetPos()
      MouseClick( "left", $w2[0],$w2[1], 1, 1 )
      while $j < $bmp[2]-1 And $tab3d[$i][$j] = $tab3d[$i][$j+1]
        $j += 1
        MouseDown( "left" )
        $w2 = MouseGetPos()
        MouseMove( $w2[0]+2, $w2[1], 0 )
      WEnd
      MouseUp("left")
      $w2 = MouseGetPos()
      MouseMove( $w2[0]+2, $w2[1], 0 )
    EndIf
    if $tab3d[$i][$j]='FFFFFF' Then
      $w2 = MouseGetPos()
      MouseMove( $w2[0]+2, $w2[1], 0 )
    EndIf
  Next
  MouseMove( $w1[0], $w1[1]+2, 0 )
Next

 

  • Like 1

Share this post


Link to post
Share on other sites
polaski

Thanks. Solved. I will try to use that code to program my CNC drill :).

It helps me alot to understand: how read arrays better.

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  

  • Similar Content

    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
    • Dzenan03
      By Dzenan03
      I want to make a while loop, that creates variables based on a array. For thist I created the array $iDsO with the number and the name of folders in an other folder. Every folder has a different name an I want to create variables(arrays) for each folder that show me all the files in that folder. For example: I have the Folder \Folder1. In it there are the Folders \1, \2, \3. In 1, 2 and 3 there are some files(.png). The array for Folder1 is $iDsO and now I want to crate the arrays $iDsO1, $iDsO2 and $iDsO3 with the files in them can I make something like this:
      While $iDs > 0 ;$iDs is the number of files in Folder1>> $iDsO[0] $iDs#here should come the Foldername for example '1'# = _FileListtoArray(@ProgramFilesDir&"\Folder1\"&$iDsO[$iDs]) $iDs = $iDs - 1 Wend So that in the End I have three variabels ($iDs1, $iDs2 and $iDs3)
       
      Is this posible or if not what could I do instead ( I don´t know the number of folders in Folder1 in the begining).
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
×