【发布时间】:2013-01-02 12:02:04
【问题描述】:
我很惊讶,因为我找不到任何从原始数据加载图像的方法。有什么优雅的方法吗?我只需要从原始位图二进制数据(无标题)创建一个 QImage 或类似的。
【问题讨论】:
我很惊讶,因为我找不到任何从原始数据加载图像的方法。有什么优雅的方法吗?我只需要从原始位图二进制数据(无标题)创建一个 QImage 或类似的。
【问题讨论】:
您可以使用带有 uchar 数组的 ctor 从原始数据创建一个 QImage 对象。 您需要指定提供给 QImage 的数据格式(RGB、RGBA、Indexed 等)
QImage ( uchar * data, int width, int height, Format format )
QImage ( const uchar * data, int width, int height, Format format )
QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )
QImage ( const uchar * data, int width, int height, int bytesPerLine,
Format format )
http://doc.qt.digia.com/qt/qimage.html
例如:
uchar* data = getDataFromSomewhere();
QImage img(data, width, height, QImage::Format_ARGB32);
希望对您有所帮助。
【讨论】:
你的问题不清楚。使用 Qpixmap。和 Qbyte 数组。这很容易。
QPixmap pic;
pic.loadFromData(array); //array contains a bite array of the image.
label->setPixmap(pic); //do what ever you want from the image. here I set it to a lable.
【讨论】: