[Qt-interest] How can I read a large image fastly?

Lorenzo Masini lorenxo86 at gmail.com
Thu Feb 4 15:51:48 CET 2010


Il giorno gio, 04/02/2010 alle 20.47 +0800, Kermit Mei ha scritto:
> Hello community!
> 
>      I run Qt on a slow embedded device, now we want to show some large 
> image on it, but the speed of loading is too slowly. For example, if we 
> decode a 6M jpg picture, we always need 100s to show it.
> 
>     Does Qt4 can support that  read  parts of  the  image to make it 
> shows quickly. For example, the picture is 4000x4000,  in fact we just 
> need to show 320x240. Can I just show a part of the picture to make it 
> faster?
> 
> I use QImageReader like this:
> 
> void Browser::paintEvent(QPaintEvent *event) {
>     imgReader->setFileName("./test.jpg");
>     imgReader->setClipRect(QRect(0,0,320,240));
>     imgReader->setScaledSize(QSize(3200,2400));
>     qDebug("canRead: %d",imgReader->canRead());
>     QPainter p(this);
>     p.drawImage(QRect(0,0,320,240),imgReader->read());
> }*
> **
> *But it shows all the picture which is reduced to 320x240, so the speed 
> is also slow.
> 
> Is there something wrong of the code?

The paintEvent isn't the right place to load an image.
It is called every time is performed an update. For example on
resizeEvent. 

I think you have to load the image into another part of your code, cache
the resulting image, and then display it into the paintEvent.

I don't understand if you need to show a part of the image or the image
resized.

cheers
Lorenzo







More information about the Qt-interest-old mailing list