QImage has the following constructor:
QImage(const QString &fileName, const char *format = nullptr);
However, I am trying to parse JPEG/PNG images that are already loaded as byte array. QImage also has other constructors, but those take already uncompressed byte array of ARGB values.
Is there a way to create QImage from unparsed byte data instead of file?
You can construct an empty QImage and then later use QImage::loadFromData(const QByteArray&) without specifying a format. QImage will then try to read the image header to guess the file format.
QByteArray bytes; //contains image file contents
QImage img;
bool success = img.loadFromData(bytes);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With