2

Recently I started working with PIL together with AutoPy to automate some tasks. One of the core functions AutoPy is needed for is its suprisingly fast (though buggy, but there are fixes for that - the build and installation from source can be annoying, and if you get the error Unable to find vcvarsall.bat, just google it).

But just now I ran into a problem I can't find a fix for. PIL and AutoPy use fundamentally diffrent formats for their screenshots. For AutoPy I couldnt get it to work with multiple screens, but for PIL i easily could. Now I need to convert these Images into a format AutoPy accepts - and that in a reasonable amount of time.

A theoratically possible solution:

def test(): Img = Image.open("example.png") Img.save("test.png") Img2.open("test.png")

Going by my testing, this takes roughly around 0.5 seconds to complete. Far more than the 0.1 seconds I'd need.

Jason
  • 3,330
  • 1
  • 33
  • 38
JeWe37
  • 21
  • 3
  • Did you ever find a solution? I have the exact same problem! If you found a solution, I do hope you have time to share it :-) – Vingtoft Dec 15 '17 at 22:22
  • @Vingtoft sorry to disappoint, though i did not. i ultimately ended up fixing the problem by modifying autopy's source to capture all screens(which as it turns out even is the default on linux). If it helps you replace line 70 in autopy-bitmap-module.py with rect = MMRectMake((size_t)GetSystemMetrics(SM_XVIRTUALSCREEN), (size_t)GetSystemMetrics(SM_YVIRTUALSCREEN), (size_t)GetSystemMetrics(SM_CXVIRTUALSCREEN), (size_t)GetSystemMetrics(SM_CYVIRTUALSCREEN)); Compiling autopy(the legacy C version this was about at least) can be a headache on windows but there are decent options. – JeWe37 Jul 21 '18 at 20:23

1 Answers1

2

I dug around the documentation to find a bitmap image conversion tool.

pil_im = Image.open("test.png")
pil_im = pil_im.convert(mode ="1") 
#this is to prevent a value error in the tobitmap function

pil_im = pil_im.tobitmap(im)

I had a similar problem earlier where a pyautogui screenshot was not considered the same as a recently opened png. pil_im.copy() created an image to compare with without all the formatting.

5zorro
  • 31
  • 3
  • Thanks a lot, doesn't quite do waht i needed and you're also just a little late, I ended up circumventing the problem by just changing the way the image outputted by the capture_screen function is cropped in the source. But I already know that this is going to be useful in the future. – JeWe37 Feb 21 '17 at 16:33