【发布时间】:2015-03-08 14:29:04
【问题描述】:
它会打开一个 JPEG 图像,但不会打开另一个 JPEG。目录和文件存在于我的系统上。为了便于娱乐,下面代码中使用的图像是console test 和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 应用程序。
【问题讨论】:
-
我知道在 2015 年这样说很蠢,但是如果你把第一个名字中的空格去掉会怎样?
-
我用下划线替换了空格,它仍然存在。它与文件本身(我推断)有关,与文件名无关。如果它意味着什么,ifstream 会毫无问题地打开并写入文件。
-
您是否尝试过使用可选参数强制它以特定格式加载?
-
console test.jpg实际上是一个 PNG 文件。 -
@Tay2510 根据规范。 PNG 数据流的前 8 个字节始终包含以下(十进制)值:137 80 78 71 13 10 26 10。这里 80 78 71 是 'P'、'N'、'G' 的 ASCII 码。