Results 1 to 6 of 6

Thread: Saving QImage

  1. #1
    Join Date
    Oct 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Saving QImage

    Hi.

    I have a problem saving a QImage.
    It is generated from a QGraphicsScene via the following code:

    Qt Code:
    1. QImage image(_scene->sceneRect().size().toSize(), QImage::Format_RGB32);
    2. QPainter painter(&image);
    3. _scene->render(&painter);
    4. image.save(filename);
    To copy to clipboard, switch view to plain text mode 

    _scene is a QGraphicsScene*
    and filename is a non empty string with the format("filename.png")

    image.save(filename) always return false.

    Another place in my program I save a QImage generated by setting individual pixels in the QImage and that works fine. (The format here is also .png)

    I have tried different formats by changing the filename from filename.png to filename.tiff and so on.

    Any ideas?

  2. #2
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Saving QImage

    Are you sure the scene is not empty? QImage::save() returns false if both width and height == 0

  3. #3
    Join Date
    Oct 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Saving QImage

    I will check that tomorrow. Thanks for the suggestion.

  4. #4
    Join Date
    Oct 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Saving QImage

    I've checked that the image has the correct size and it all looks right.

    Any other suggestions?

  5. #5
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Saving QImage

    The following works fine for me, I can see no difference with your code:

    Qt Code:
    1. #include <QApplication>
    2. #include <QImage>
    3. #include <QPainter>
    4. #include <QGraphicsScene>
    5.  
    6. int main(int argc, char** argv)
    7. {
    8. QApplication app(argc, argv);
    9.  
    10. scene->setSceneRect(0, 0, 2, 2);
    11.  
    12. QImage img(scene->sceneRect().size().toSize(), QImage::Format_RGB32);
    13.  
    14. QPainter painter(&img);
    15. scene->render(&painter);
    16.  
    17. bool b = img.save("test.png");
    18.  
    19. Q_ASSERT(b);
    20.  
    21. return 0;
    22. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Oct 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Saving QImage

    Thank you so much mattc for all your effort...

    Unfortunately I had made a major error in the construction of the filename... stupid... After correcting this it seems to work fine....

    very sorry for wasting everyones time...

Similar Threads

  1. qImage saving to jpg problem
    By sqarpi in forum Qt Programming
    Replies: 9
    Last Post: 1st September 2010, 15:43
  2. Saving as XML
    By rakkar in forum Newbie
    Replies: 2
    Last Post: 30th October 2009, 17:17
  3. XML saving settings
    By ^NyAw^ in forum Qt Programming
    Replies: 12
    Last Post: 12th May 2009, 17:05
  4. saving the state of the ui
    By zgulser in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2009, 12:17
  5. Replies: 3
    Last Post: 15th March 2006, 11:44

Tags for this Thread

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.