将图像从字节数组加载到图形视图中

时间:2013-08-24 11:26:51

标签: c++ qt qpixmap qbytearray

我从先前从大型游戏文件加载的原始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

1 个答案:

答案 0 :(得分:1)

错误发生在QByteArray构造函数中,我应该使用this one

相关问题