0

I'm using the C-based screenshot concept from JHolta's answer in Take a screenshot via a python script. [Linux] in order to generate screenshots I'd like to display in PyGame. With some minor tweaks (prepending extern "C" to the functions and importing Xutil instead of Xlib) the provided code works amazingly well. In short, it uses Image.frombuffer on a byte array returned by the C library. With show(), the image and anything about it I manipulate is displayed by ImageMagick.

However, if I convert it to Python 3's PyGame as per PIL and pygame.image, I only get a black surface. It's not a straightforward issue, though: If I draw onto the image before converting it into a PyGame image (like in the OP of the latter link), that does show on a black background when blitting the result. Furthermore, printing the byte objects from PILImage.tobytes and pygame.image.tostring shows they both contain data and their len is identical.

What am I doing wrong here? I'll gladly provide code if necessary, but I think it's more of a conceptual issue and I didn't really change the snippets from these answers a lot.

(Similar issue in Python 2, by the way, but there PyGame uses str instead of byte for tostring / fromstring and printing the tostring appears to yield an empty string.)

Pikaro
  • 148
  • 10

1 Answers1

1

It turns out that a buggy trigger caused the screenshoot to be taken again while the fullscreen window displaying it was opening. I suppose there are a few milliseconds of blackness or of an undefined state (in the context of the screenshot function) at that moment, and the library is fast enough to catch that.

I'm not sure if this should stay up because it's basically a reminder to check for things that a human can't perceive. Feel free to delete if it's not appropriate.

Pikaro
  • 148
  • 10
  • Wel, kudos for finding this out on your own! If you feel this might be a problem where others might run in to, leave the post here (you can even accept your own answer, some times later). Otherwise, you can delete it yourself. – Jongware Apr 08 '18 at 19:39