QImage too slow to load ...

  • Hi guys ;
    I would like to show a small thumbnail image in my app, when user selects an image file. Here is my code :

            QPixmap MyPixmap;
            MyPixmap = QPixmap (":/Images/Holder.png");
            if (!MyPixmap.isNull()) { ui->imageLabel->setPixmap ( MyPixmap.scaled ( 98,  55,  Qt::KeepAspectRatio));}

    Everything works fine for small images (700 KByte size), but it take long time to show when I load an image with 3MegaByte file size...!
    Is there a way to improve the performance ?


  • Lifetime Qt Champion

    Have you tried the 3 MB file from a
    normal file and not from a resource ?
    Just to see time difference.

  • I guess the time is not taken for loading the image but for scaling the image. If the image is loaded from resource (means: static and will not change after compilation) you should scale the image once and include the scaled version into your binary...

  • You could try out QImageReader which, for some formats, can speed up reading by reading in a scaled image.

    On top of that you could read in the image in a separate thread (in case the loading is blocking some UI you might have).

    And on top of that you could use a quicker method of scaling the image. Should you want to reuse the image, don't forget to cache the scaled image.

    PS: Also, there is no need to guess: Make use of QElapsedTimer if you want to know how long certain actions take.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.