sethmlarson / virtualbox-python

Complete implementation of VirtualBox's COM API with a Pythonic interface.
https://pypi.org/project/virtualbox
Apache License 2.0
354 stars 75 forks source link

Screenshot has wrong shape #143

Closed Karol-G closed 4 years ago

Karol-G commented 4 years ago

Hi,

I am trying to make a screenshot from my VM with:

h, w, _, _, _, _ = session.console.display.get_screen_resolution(0)
png = session.console.display.take_screen_shot_to_array(0, h, w, virtualbox.library.BitmapFormat.png)

with h= 800 and w=600. I would expect that png has also a shape of (800, 600) or at least of (480000,), however the shape is (52812,). Why could that be? I don't know if this is related to #111 as I do not get an error.

Best Karol

Karol-G commented 4 years ago

Ok I manged to fix it myself:

from PIL import Image
from io import BytesIO

h, w, _, _, _, _ = session.console.display.get_screen_resolution(0)
image_data = session.console.display.take_screen_shot_to_array(0, h, w, virtualbox.library.BitmapFormat.png)
image_data = BytesIO(image_data)
image = Image.open(image_data)