我在从之前从大型游戏文件加载的原始 bmp 数据加载图像数据时遇到了一些问题。
我确定数据没问题,因为未到达 else
分支,但未显示图像。
也许我没有以正确的方式使用 loadFromData
?
以前有人遇到过这个问题吗?
QByteArray buff((this->current_object->image_buffer));
QPixmap pixmap;
if(pixmap.loadFromData(buff)){
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
this->scene->addItem(item);
this->ui->graphicsView->update();
}else{
QMessageBox::information(0, "Error.", "Could not convert BMP image.");
//TEST IF BITMAP IS CORRECT
FILE *pFile = fopen("/home/konstanty/img.bmp", "wb");
for(int j=0;j<this->current_object->bitmap_size;j++){
fwrite (&this->current_object->image_buffer[j], 1 , 1 , pFile);
}
fclose(pFile);
QPixmap imgg("/home/konstanty/img.bmp");
qDebug() << imgg.isNull(); // output - false
最佳答案
错误在 QByteArray 构造函数中,我应该使用 this one .
关于c++ - 从字节数组加载图像到图形 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18418058/