Results 1 to 2 of 2

Thread: QImage loadFromData

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default QImage loadFromData

    Hi trolltechers,

    I'm trying to load an image and then populate another using its "binary data",
    For some reason it doesn't work and image2 isn't saved.

    Here is the code :

    Qt Code:
    1. QImage image("tata.png");
    2.  
    3. unsigned char * bits = image.bits();
    4.  
    5. QImage image2;
    6. image2.loadFromData(bits, image.numBytes() * 8);
    7. image2.convertToFormat(QImage::Format_ARGB32);
    8.  
    9. QString photoPath = "toto.png";
    10.  
    11. if (image2.save(photoPath) == NULL)
    12. {
    13. // Enters here : Image2 cannot be saved
    14. }
    To copy to clipboard, switch view to plain text mode 

    Any idea ?

  2. #2
    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: QImage loadFromData

    What does loadFromData() return? It requires not only the pixel data but also the header to be present.

Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 16:37
  2. 2 questions on QPrint + QImage + PDF
    By jiveaxe in forum Qt Programming
    Replies: 5
    Last Post: 16th January 2008, 12:06
  3. QImage loadFromData not run... XPDF data
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 24th April 2007, 11:51
  4. how to use loadFromData in painter
    By sar_van81 in forum Qt Programming
    Replies: 18
    Last Post: 31st January 2007, 04:09
  5. QImage constructor
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 12:06

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.