2

我很惊讶,因为我找不到任何从原始数据加载图像的方法。有什么优雅的方法吗?我只需要从原始位图二进制数据(无标题)创建一个 QImage 或类似的。

4

2 回答 2

3

您可以使用带有 uchars 数组的 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);

希望有帮助。

于 2013-01-02T13:17:23.337 回答
-1

你的问题不清楚。使用 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.
于 2013-01-02T13:49:27.507 回答