PDA

View Full Version : scanning images



sriluyarlagadda
9th May 2008, 10:34
hi,

I am relatively new to QT, I am developing a photo management application in which i need to
scan all the images in the filesystem(i'm using fedora core) . Along with QFileinfo and QDirIterator, I need a function which reads a file and determines whether it is an image(irrespective of the extension)...can QImageReader.canRead() do the job?It should also deal with the case where we rename a text file into an image.

Also I wish to know if we can use exif information of an image through qt

i tried using canRead function on a jpeg file(a true image) and it returned false when i used the error() function it showed devise error. wat might be wrong?

any help would be appreciated

thankyou

srihari

wysota
9th May 2008, 11:04
can QImageReader.canRead() do the job?
Yes.


It should also deal with the case where we rename a text file into an image.
It will.


Also I wish to know if we can use exif information of an image through qt
Probably not all info, but QImage has some method of retrieving information related to an imege. If that's not enough, you'll have to use a separate library (libexif probably).


i tried using canRead function on a jpeg file(a true image) and it returned false when i used the error() function it showed devise error. wat might be wrong?
You might have passed it an incorrect file name or a device it couldn't read.

sriluyarlagadda
9th May 2008, 11:15
no i used the correct file name with a proper url(I used the same url to load an icon into a qlistwidget and it worked) . I used the setFileName function of qimage reader.I am pasting the code for u to look.


#include <QImageReader>
#include <stdio.h>

int main(int argc,char* argv[])
{
QImageReader *imageRead=new QImageReader();
imageRead->setFileName("/home/srihari/CompaqCity.jpg");
bool b;
b=imageRead->canRead();
if(b)
{
printf("true\n");
}
else
printf("false\n");

int value=imageRead->error();
printf("%d",value);
}

sriluyarlagadda
9th May 2008, 11:43
guys plz help u out. I need this fixed to continue on my work......

sriluyarlagadda
9th May 2008, 11:48
sry plz help *me out

lszk
9th May 2008, 12:26
int value=imageRead->error();
printf("%d",value);
Which error number you have? I've got a number 3 on jpg files. It's mean that, a qt doesn't support jpg files (QImageReader::UnsupportedFormatError). I don't know why. I think packager didn't apply a properly flag to this kind of file. I have Fedora too (7).

With bmp files, this code works.

sriluyarlagadda
9th May 2008, 12:31
I got 2 and I used jpeg

sriluyarlagadda
9th May 2008, 12:33
mine's device error

wysota
9th May 2008, 12:37
JPG files might need a plugin to work. If you installed Qt from binary packages, you probably need to install some other packages as well.

If one image doesn't work, try another - especially PNG, support for them is embedded into Qt itself so it should always work. The device error is most likely caused by some permissions problem - check if you have read permissions for the file. You can test with a simple program:

QFile file("/home/..../...jpg");
if(file.isReadable()) qDebug() << "readable";
qDebug() << file.open(QFile::ReadOnly);

You should get "readable" and "true".