我写了下面的一个小程序,想要计算一下图像的长和宽,但是输出的内容却是两个0。
我已经把图片放在了该项目的文件夹里,现在想知道该图像是否被真正的读取,麻烦大家帮我看看应该怎么样获取图像的信息,或是怎么样能将该图像给显示出来呢?
#include<iostream>
#include <QWidget>
#include<QPainter>
#include<QImage>
#include<QApplication>
#include <QPlastiqueStyle>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QApplication::setStyle(new QPlastiqueStyle);
QImage tmpImg("boy.jpg", "Format_RGB32");
int widgetWidth;
int widgetHeight;
widgetWidth = tmpImg.width(); //Returns the width of the image
widgetHeight = tmpImg.height();
cout<<widgetWidth<<endl<<widgetHeight<<endl;
return a.exec();
}