【问题标题】:Loading an image onto a graphics view from a byte array将图像从字节数组加载到图形视图中
【发布时间】:2013-08-27 09:41:44
【问题描述】:

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

【问题讨论】:

    标签: c++ qt qpixmap qbytearray


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 2015-01-07
      • 2014-12-14
      相关资源
      最近更新 更多