[英]Load QImage from byte array without knowing the format
QImage
has the following constructor: QImage
具有以下构造函数:
QImage(const QString &fileName, const char *format = nullptr);
However, I am trying to parse JPEG/PNG images that are already loaded as byte array. 但是,我试图解析已经作为字节数组加载的JPEG / PNG图像。
QImage
also has other constructors, but those take already uncompressed byte array of ARGB values. QImage
还具有其他构造函数,但这些构造函数采用了未经压缩的ARGB值字节数组。
Is there a way to create QImage
from unparsed byte data instead of file? 有没有一种方法可以从未解析的字节数据而不是文件创建
QImage
?
You can construct an empty QImage
and then later use QImage::loadFromData(const QByteArray&)
without specifying a format. 您可以构造一个空的
QImage
,然后在不指定格式的情况下使用QImage::loadFromData(const QByteArray&)
。 QImage
will then try to read the image header to guess the file format. 然后,
QImage
将尝试读取图像标题以猜测文件格式。
QByteArray bytes; //contains image file contents
QImage img;
bool success = img.loadFromData(bytes);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.