這兩天一直被Qt顯示圖片的代碼搞的惱火,在網上查的時候發現Qt明明支持對.bmp文件格式的圖片顯示,但是一直顯示不了,最後改爲.png就可以了,代碼簡單,但是確實對這個問題表示不解:
#ifndef XIANSHI_H
#define XIANSHI_H
#include <QtWidgets/QWidget>
#include "ui_xianshi.h"
#include<QLabel>
#include<QMovie>
#include<QImage>
class xianshi : public QWidget
{
Q_OBJECT
public:
xianshi(QWidget *parent = 0);
~xianshi();
QImage image;
private:
Ui::xianshiClass ui;
};
#endif
#include "xianshi.h"
xianshi::xianshi(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
//movie=new QMovie("D:/sd.bmp");
//image=new QImage("D:/sd.bmp");
image.load("D://df.png");
ui.label->setPixmap(QPixmap::fromImage(image));
ui.label->show();
}
xianshi::~xianshi()
{
}