QPixmap 不打开一些图像
QPixmap does not open some image
它打开一张 JPEG 图片,但不能打开另一张 JPEG。目录和文件存在于我的系统上。为了便于娱乐,下面代码中使用的图像是 console test and f2.
#include "mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
QPixmap *pixmap = new QPixmap;
pixmap->load("C:/Programs/console test.jpg");
if(pixmap->isNull())
cout << "darn" << endl;
else
cout << "not null" << endl;
pixmap->load("C:/Programs/f2.jpg");
if(pixmap->isNull())
cout << "darn" << endl;
else
cout << "not null" << endl;
return a.exec();
}
以上代码打印
darn
not null
如果相关,应用程序是 QWidget 应用程序。
console test.jpg is actually a PNG file. – Oktalist
Oktalist 回答了问题。我天真地使用并将扩展名从 png 更改为 jpg 期望文件转换。用同样的方法撤销修改后,图片成功打开
ifstream src("console print.jpg", ios::binary);
ofstream dest("console print.png", ios::binary);
dest << src.rdbuf();
dest.flush();
现在控制台打印具有正确的文件扩展名。它打开了。有十亿种其他方法可以做到这一点,但这个很简单。
-桑弗
它打开一张 JPEG 图片,但不能打开另一张 JPEG。目录和文件存在于我的系统上。为了便于娱乐,下面代码中使用的图像是 console test and f2.
#include "mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
QPixmap *pixmap = new QPixmap;
pixmap->load("C:/Programs/console test.jpg");
if(pixmap->isNull())
cout << "darn" << endl;
else
cout << "not null" << endl;
pixmap->load("C:/Programs/f2.jpg");
if(pixmap->isNull())
cout << "darn" << endl;
else
cout << "not null" << endl;
return a.exec();
}
以上代码打印
darn
not null
如果相关,应用程序是 QWidget 应用程序。
console test.jpg is actually a PNG file. – Oktalist
Oktalist 回答了问题。我天真地使用并将扩展名从 png 更改为 jpg 期望文件转换。用同样的方法撤销修改后,图片成功打开
ifstream src("console print.jpg", ios::binary);
ofstream dest("console print.png", ios::binary);
dest << src.rdbuf();
dest.flush();
现在控制台打印具有正确的文件扩展名。它打开了。有十亿种其他方法可以做到这一点,但这个很简单。
-桑弗