从Qt中的QByteArray加载QPixmap吗? [英] Load QPixmap from QByteArray in Qt?

查看:263
本文介绍了从Qt中的QByteArray加载QPixmap吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节数组,其中包含图像的内容(png/bmp或其他格式).

I have a byte array with the contents of an image (in png/bmp or some other format).

如何将其加载到QPixmap中?

How can I load it into a QPixmap?

推荐答案

bool QPixmap::loadFromData ( const QByteArray & data, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )

这里的格式是字符串文字,如"PNG"或类似的内容

Format here is string literal like "PNG" or something similar

QPixmap p;
QByteArray pData;
// fill array with image
if(p.loadFromData(pData,"PNG"))
{
   // do something with pixmap
}

这篇关于从Qt中的QByteArray加载QPixmap吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆