The script takes 3.75 seconds to run, and I need help refining the code to make it faster.
I have to run this on 10,000 png files, and at its current speed, and it would take over 10 hours.
I haven't tried to use PixelSearch or ImageSearch. PixelGetColor seemed most appropriate for this, correct me if I'm wrong.
I have already tried optimizing my code as you can see in the beginning of the script below, but it did not improve the performance. You can see the code below. Maybe using an object array instead of a string?
To test my code, simply adjust the FirstBoxPosX and FirstBoxPosY values to fit your monitor. Since I'm using CoordMode, Pixel, Screen, you might also have to adjust the BoxSize value so it jumps to next box correctly, depending how much you scale the png on your screen. I used "Windows Spy" to find the values.
p.s. Using Window or Client in CoordMode might eliminate having to maintain the PNG at the same location and scale for the script to work. Any ideas? (Maybe if I convert the PNG to a BMP, the code would work better with a bitmap?)
I appreciate all of your help!
Here's the grid:
Here's the output:
Here's the code:
Code: Select all
#NoEnv
#KeyHistory 0
#NoTrayIcon
#SingleInstance Force ;Skips the dialog box and replaces the old instance automatically.
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
;OPTIMIZATIONS END
PuzSize:= 15
BoxSize:= 35
FirstBoxPosX:= 2618
FirstBoxPosY:= 542
StartMidBoxX:= FirstBoxPosX + (BoxSize / 2)
StartMidBoxY:= FirstBoxPosY + (BoxSize / 2)
CurrX:= StartMidBoxX
CurrY:= StartMidBoxY
StartTime := A_TickCount
CoordMode, Pixel, Screen
Loop % PuzSize
{
Loop % PuzSize
{
PixelGetColor, color, %CurrX%, %CurrY%
colors .= color
CurrX += BoxSize
}
CurrY += BoxSize
CurrX:= StartMidBoxX
colors .= "`n"
}
colors:= StrReplace(colors, "0xFCFEFC", " ⬜ ")
colors:= StrReplace(colors, "0x040204", " ⬛ ")
ElapsedTime := A_TickCount - StartTime
MsgBox, %ElapsedTime% milliseconds have elapsed.
msgbox % colors
ExitApp