Results 1 to 15 of 15

Thread: Qt displays large size jpg

  1. #1

    Default Qt displays large size jpg

    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::keepAsp ectRatio));

    Regards,
    omegas

  2. #2
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt displays large size jpg

    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:

    Qt Code:
    1. QImageReader imageReader(fileName);
    2. imageReader.setScaledSize(sizeLoaded);
    3. QImage loadedImage = imageReader.read();
    To copy to clipboard, switch view to plain text mode 

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

  3. The following user says thank you to Luc4 for this useful post:

    JohannesMunk (21st April 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt displays large size jpg

    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.

  5. #4

    Default Re: Qt displays large size jpg

    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
    omegas

  6. #5
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt displays large size jpg

    1. Qt Creator should list the methods I suppose. Does it build?
    2. sizeLoaded is the size of the image once loaded.

  7. #6

    Default Re: Qt displays large size jpg

    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

  8. #7

    Default Re: Qt displays large size jpg

    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::KeepAsp ectRatio));
    imageLabel->setPixmap(pixmap);

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt displays large size jpg

    I don't think jpeg supports scaled size loading.

    This line doesn't make any sense, though:
    Qt Code:
    1. imageReader.setScaledSize(imageReader.scaledSize() );
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt displays large size jpg

    Quote Originally Posted by omegas View Post
    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::KeepAsp ectRatio));
    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.

    Quote Originally Posted by wysota View Post
    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.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt displays large size jpg

    I think you are right:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv){
    4. QApplication app(argc, argv);
    5. QImageReader reader("img.jpg", "JPEG");
    6. qDebug() << "QImageIOHandler::Size:" << reader.supportsOption(QImageIOHandler::Size);
    7. qDebug() << "QImageIOHandler::ScaledSize:" << reader.supportsOption(QImageIOHandler::ScaledSize);
    8. }
    To copy to clipboard, switch view to plain text mode 
    $ ./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.

  12. #11

    Default Re: Qt displays large size jpg

    Quote Originally Posted by Luc4 View Post
    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

  13. #12
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt displays large size jpg

    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:

    Qt Code:
    1. QImageReader imageReader(fileName);
    2. imageReader.setScaledSize(QSize(2000, 2000));
    3. QImage imageInMemory = imageReader.read();
    To copy to clipboard, switch view to plain text mode 

    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.

  14. #13

    Default Re: Qt displays large size jpg

    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

  15. #14
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt displays large size jpg

    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.

  16. #15

    Default Re: Qt displays large size jpg

    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

Similar Threads

  1. QTableView and changing how a cell displays its contents
    By BitRogue in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2009, 10:18
  2. Multiple displays on X11
    By alisami in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2009, 17:25
  3. QMenu always displays icons aty 16x16 px
    By ghassett in forum Qt Programming
    Replies: 3
    Last Post: 21st May 2009, 18:41
  4. Sending large datagrams(very large)
    By marcel in forum General Programming
    Replies: 1
    Last Post: 16th February 2008, 21:55
  5. QLabel, large, rich text, font size
    By TheKedge in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2007, 11:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.