Reputation: 53119
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?
Upvotes: 2
Views: 3832
Reputation: 4021
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);
Upvotes: 8