PDA

View Full Version : Qt displays large size jpg



omegas
20th April 2010, 07:07
Dear all,

I have trouble displaying large size jpg files in my arm board. My program works for png and jpg which size is under 1mb. It will show error "Pixmap is a null pixmap" if the jpg file is over 2mb or above.

Does anyone know how to display large size jpg in arm board? Here is the method I used....

QImage image(filePath);
QPixmap pixmap = QPixmap::fromImage(image);
imageLabel->setPixmap(pixmap.scaled(pixmap.size(),Qt::keepAspe ctRatio));

Regards,
:mad:omegas

Luc4
20th April 2010, 09:13
Have you tried using QImageReader? It is possible, for the supported formats, to load an image in a specified size. This would avoid the loading of the entire image. Something like this:


QImageReader imageReader(fileName);
imageReader.setScaledSize(sizeLoaded);
QImage loadedImage = imageReader.read();

This way you should be able to read larger images and to do it faster.

wysota
20th April 2010, 13:18
2MB jpeg file contains about 24MB of image data (typical jpeg compression is about 1:12). Make sure your device is able to handle as much graphics data.

omegas
20th April 2010, 15:26
Hi all,


Thanks for your replies and I will try it but before that I still have a few questions..


1. I put the above codes in my programs and when I dot the ImageReader QT did not show its properties out ...is it normal cos I have already include <QtGui/QImageReader>.

2. imageReader.setScaledSize(sizeLoaded); ==> what value should I put in variable "sizeLoaded" ?


Thanks
:confused:omegas

Luc4
20th April 2010, 16:05
1. Qt Creator should list the methods I suppose. Does it build?
2. sizeLoaded is the size of the image once loaded.

omegas
21st April 2010, 05:29
When I checked Qt documentation, the value of sizeLoaded should be a QSize type. Since I am new in Qt, what possible values for I set for this QSize type? A number of pixel or a number of other measurement?

Oh, by the way question one is solved. I reload Qt creator and it list the method.

Regards,
omegas

omegas
21st April 2010, 05:45
I have tried the program but it gave me nothing on the screen with no error. what happened?

the codes:

QImageReader imageReader(filePath);
imageReader.setScaledSize(imageReader.scaledSize() );
QImage image = imageReader.read();
//QImage image(filePath);
QPixmap pixmap = QPixmap::fromImage(image);
//imageLabel->setPixmap(pixmap.scaled(pixmap.size(),Qt::KeepAspe ctRatio));
imageLabel->setPixmap(pixmap);

wysota
21st April 2010, 07:51
I don't think jpeg supports scaled size loading.

This line doesn't make any sense, though:

imageReader.setScaledSize(imageReader.scaledSize() );

Luc4
21st April 2010, 08:17
I have tried the program but it gave me nothing on the screen with no error. what happened?

the codes:

QImageReader imageReader(filePath);
imageReader.setScaledSize(imageReader.scaledSize() );
QImage image = imageReader.read();
//QImage image(filePath);
QPixmap pixmap = QPixmap::fromImage(image);
//imageLabel->setPixmap(pixmap.scaled(pixmap.size(),Qt::KeepAspe ctRatio));
imageLabel->setPixmap(pixmap);

I see that, by default, the method scaledSize() returns a Qsize (-1, -1). Maybe that's the reason why you get nothing on the screen. You have to set it to the size in pixel you want the image to be loaded into memory.


I don't think jpeg supports scaled size loading.

As far as I can see yes... I create thumbnails using this technique and works greatly! Moreover I can load very large images that were not loaded otherwise.

wysota
21st April 2010, 08:41
I think you are right:

#include <QtGui>

int main(int argc, char **argv){
QApplication app(argc, argv);
QImageReader reader("img.jpg", "JPEG");
qDebug() << "QImageIOHandler::Size:" << reader.supportsOption(QImageIOHandler::Size);
qDebug() << "QImageIOHandler::ScaledSize:" << reader.supportsOption(QImageIOHandler::ScaledSize) ;
}

$ ./imr
QImageIOHandler::Size: true
QImageIOHandler::ScaledSize: true

Just note scaled loading would work even if ScaledSize returned false here. Only that the whole image would be loaded first and scaled later.

omegas
21st April 2010, 09:04
I see that, by default, the method scaledSize() returns a Qsize (-1, -1). Maybe that's the reason why you get nothing on the screen. You have to set it to the size in pixel you want the image to be loaded into memory.



As far as I can see yes... I create thumbnails using this technique and works greatly! Moreover I can load very large images that were not loaded otherwise.


Dear Luc4,

Could you give me a more specific example how to use setScaledSize function since I am a little bit puzzled by it?

omegas

Luc4
21st April 2010, 09:19
Well... You can choose whatever size you want I suppose. That's up to you... Let's say you have a very large image, 10000x10000. It's possible an embedded device is unable to load it. So, assuming the format is supported, you can load it in memory in a scaled size, so that you have, let's say, 2000x2000 pixels. So:


QImageReader imageReader(fileName);
imageReader.setScaledSize(QSize(2000, 2000));
QImage imageInMemory = imageReader.read();

This will load into memory 2000x2000 pixels, and it never needs to load entirely the 10000x10000 pixels. Very useful in case you have not enough memory to do so. According to the documentation, the scaling is performed using the scale() method of QImage and the SmoothScaling algorithm. imageInMemory will be a 2000x2000. Information is clearly lost.

omegas
21st April 2010, 09:28
Thanks Luc4... I will try that ....by the way Do u have any experiences on developing arm linux app. for displaying large size image? If so, what is the best Qsize() of pixel for arm app.? I am currently using s3c2440 arm board and I just tried the program but it gave me segmentation fault....maybe it is not the setting or program problem and it may be the problem of my cross compiler since I am using version 4.3.2 EABI one. According to my people comments, if u use this compiler it will always give u segmentation fault error but 4.1.2 is ok...I think I will change it later. Still , please provide any valuable info. from the above...

Regards,
omegas

Luc4
21st April 2010, 11:51
I suppose the choice of the size is more something related to the amount of memory and to the application you're developing. The more pixels you use, the more memory you'll use and the more time will be needed to load large images. What you could do is to load images up to a max size, and then reload only a specific rect in case zooming is required.
I've never experience any segfaults however.

omegas
22nd April 2010, 05:07
Hi again,


It works now. As you mentioned above it may be the cause of memory loaded and after I choose to load the image size by 1/10 or above of it, the images showed up. i.e. imagereader.setScaledSize(imagereader.scaledsize/10).


Thanks for all your valuable assistants.

Cheers,
omegas