It looks like you're new here. If you want to get involved, click one of these buttons!
I'm trying to convert the image/screenshot of the current view to a base64 string.
In c++ I would have done something like this:
QByteArray byteArray; QBuffer buf(&byteArray); QImage viewPortImage(100,100,QImage::Format_ARGB32); viewPortImage.save(&buf, "png"); std::string encoded = byteArray.toBase64().toStdString();
I'm not able to translate this for the usage with the Python interpreter and pya, since QByteArray is not wrapped (and possibly other issues).
Trying to get the raw data with the following code fails:
view = pya.Application.instance().main_window().current_view() viewPortImage = view.get_image(100,100) viewPortImage.bits()
with: "'utf-8' codec can't decode byte 0xff in position 0: invalid start byte in QImage_Native.bits"
The wrapper documentation tells me that the data is converted to a python string, which apparently fails.
Signature: [const] string bits
Description: Method const unsigned char *QImage::bits()
Right now I'm using
view.save_image(imagePath,100,100) to save the image to disk where I can open the file and encode it with python's base64, but I'm wondering if there's a better solution.