2013-08-24 94 views
0

我從加載以前從大型遊戲文件加載的原始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

錯誤是在QByteArray構造函數中,我應該使用this one