程序代码如下,使用QLabel显示Pixmap,QImage读取图像文件:
    QImage image(filename);
    if (image.isNull()) {        
QMessageBox::information(this, tr("Image Viewer"),
            tr("Cannot load %1.").arg(filename));
        //return;
    };
    QPixmap *pixmap = new QPixmap;
    pixmap->fromImage(image);
    pixmap->scaled(size,Qt::KeepAspectRatio);
    setPixmap(*pixmap);
编译通过,但是运行的时候什么也不显示,输出栏提示QImage::scaled: Image is a null image
懵了……大侠帮忙……
PS:File  --读取-->  QImage  --加载--> QPixmap  --显示-->  QLabel  这个顺序不要改哦……
PPS: 使用setPixmap(QPixmap::fromImage(image));显示就可以……这是为什么呢……
[ 此贴被米尔利安在2008-11-18 11:04重新编辑 ]