[Qt-interest] How can I read a large image fastly?
Jeroen De Wachter
jeroen.dewachter at barco.com
Thu Feb 4 17:14:59 CET 2010
Hello Kermit,
I don't know how much storage you have on your device, but it might not
be a bad idea to just store the same images in multiple sizes. That way
you can load the thumbnail version (which shouldn't take as long to
parse) and get the full image when you need it.
I think there are also image formats out there that allow loading an
image with incremental quality. The beginning of the file gets you
enough information to draw a low resolution/low quality image and the
more file you parse, the more resolution/quality you get. I know this
was used in a lot of (I think JPEG) images during the early days of the
Internet (low bandwidth) to allow large images to load in the background
while a lower quality image was already showing. I haven't seen that in
the last few years though...
You may be able to use this sort of thing to load the lower resolution
image and then read the rest of the file in the background to display at
the time you need full resolution.
I have no idea if anything in Qt supports this though, so you may end up
needing to write your own image reader for this (and probably some
handling code, as I don't think Qt supports incremental quality images
anyway, but I may be wrong about this).
Anyway, just floating some ideas your way
Kind regards,
Jeroen
On Thu, 2010-02-04 at 15:08 +0000, Dan Milburn wrote:
> Kermit Mei wrote:
> > 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?
>
> Ok, I am not familiar with QImageReader, but a quick look at the docs
> suggests this is what your code is doing:
>
> - Using setClipRect() to only read part of the image.
> - Scaling that part of the image up to 3200x2400.
> - Drawing the image scaled back down to 320x240.
>
> It's hardly surprising if this works slowly, even without the fact that
> as others have told you, paintEvent() is the wrong place to be doing this.
>
> It's unclear what you're actually trying to achieve. If you want to
> draw the entire image scaled down there is no way to avoid loading the
> full image. You should remove the setClipRect() call and
> setScaledSize( 320, 240 ). This is unlikely to be any faster than using
> QImage::scale() directly.
>
> There really isn't a way to load large images any faster. You can make
> it *seem* faster if you can load them ahead of time, possibly in another
> thread.
>
> See for example
> http://labs.trolltech.com/blogs/2010/01/21/qt-graphics-and-performance-generating-content-in-threads/
>
> Dan
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.
More information about the Qt-interest-old
mailing list