So what I'm doing is taking screenshots of screen, getting the pixel RGB value, and putting it in another image. The code can be found here or below. Everything works fine, except it's slow, and makes the system a little slow too (when sleep time is 0).
import time
import Image
import ImageGrab
X = 0 # seconds to pause before taking next pixel
WIDTH = 300 # the width of the image drawn, higher number = slower
HEIGHT = 300 # the height of the image drawn, higher number = slower
if __name__ == '__main__':
#start = time.time()
pixels_img = Image.new('RGB', (WIDTH, HEIGHT), 'black') # create a new Image instance
pixels = pixels_img.load()
for w in xrange(WIDTH):
for h in xrange(HEIGHT):
img = ImageGrab.grab() # take a screenshot
img = img.resize((WIDTH, HEIGHT)) # create a thumbnail
pixels[w, h] = img.getpixel((w, h)) # pixels(x, y) = (r, g, b)
time.sleep(X)
pixels_img.save('pixel.png', 'PNG')
pixels_img.show()
#print time.time() - start
I tried with image size 100 px, and it took about 19 minutes. This is a lot considering I'd need a much bigger image to get a better and usable script.
How do I:
- Make the script much, much faster?
- Make it use less system resources?