一种使用QImageReader加载图片的方法,图片大小为12M
QString strPath = QString("image.jpg");
qDebug() << "start=========" << QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
QMimeDatabase db;
//判断文件类型
QMimeType mime = db.mimeTypeForFile(strPath, QMimeDatabase::MatchMode::MatchContent);
std::string strSuffix = mime.preferredSuffix().toStdString();
QImage image;
std::unique_ptr<QImageReader> imgRead(new QImageReader(strPath, strSuffix.c_str()));
qint64 nSize = imgRead->device()->size();
int nWidth = imgRead->size().width();
int nHeight = imgRead->size().height();
//缩放
// imgRead->setScaledSize(QSize(450, 500));
image = imgRead->read();
QPixmap pixmap = QPixmap::fromImage(image);
ui->label_image->setPixmap(pixmap);
qDebug() << "end===========" << QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
start=========== “20:00:57.196”
end=========== “20:00:57.608”