Keep Screen (screen.keep)
Declaration
screen.keep()
Description
Cache the current screen image into a buffer. When calling color picking, color finding, screenshot, image finding functions multiple times, data will be read from the cached buffer instead of the live screen, improving performance.
This is an optimization function for heavy static image processing.
It ONLY affects XXTouch's capture/color functions and does NOT freeze the actual device screen.
Example
-- Loop and sample colors of 6144 points, output to log
t = {}
screen.keep()
for k = 1, 640, 10 do
for j = 1, 960, 10 do
-- format as hex string
t[#t + 1] = string.format("%X", screen.get_color(k, j))
end
end
screen.unkeep()
nLog(t)
Note: Uses nLog
Notes
- Two consecutive separate
screen.get_color
calls on the same position may get different values.- Without
screen.keep
, a singlescreen.get_color
call costs about the same as onescreen.keep
.- After
screen.keep
, about 50 consecutivescreen.get_color
calls cost about the same as onescreen.keep
.