• 4848阅读
  • 1回复

图像问题 [复制链接]

上一主题 下一主题
离线dltanglin
 

只看楼主 倒序阅读 楼主  发表于: 2010-08-05
关键词: 图像
我写了下面的一个小程序,想要计算一下图像的长和宽,但是输出的内容却是两个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();
}
离线dbzhang800

只看该作者 1楼 发表于: 2010-08-05
建议再看看 QImage 的manual

1. 文件路径,如果你对"当前工作目录",“可执行程序所在目录”等不了解,最好不要用相对路径,改为绝对路径
2. 参数错误,format 是指 png gif jpg 这些
3. 如果想知道是否加载成功,考虑用 QImage 的 load 函数
快速回复
限100 字节
 
上一个 下一个