Results 1 to 6 of 6

Thread: Convert QPixmap to QByteArray ?

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Convert QPixmap to QByteArray ?

    I am using a QPixmap to take a screenshot of my desktop. I would like to convert this QPixMap to QByteArray.

    How ?

  2. #2
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Convert QPixmap to QByteArray ?

    Have you tried it using QPixmap::save. From the Qt Docs:

    Qt Code:
    1. QPixmap pixmap;
    2. QByteArray bytes;
    3. QBuffer buffer(&bytes);
    4. buffer.open(QIODevice::WriteOnly);
    5. pixmap.save(&buffer, "PNG");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert QPixmap to QByteArray ?

    Thanks for the answer.

    Now I have everything in a QByteArray. Now, I am parsing my QByteArray which has XML format. The parsing is done with DOM.

    I need an element of the XML (QByteArray) to be comverted or used as QByteArray.

    How ?

    I do not want to transform the element to string, because I think I will loose the picture.

    Qt Code:
    1. void Message :: parseScreenshot(QByteArray incomingMessage)
    2. {
    3. QDomDocument doc("messageIn");
    4. doc.setContent(incomingMessage);
    5. QDomElement docElem = doc.documentElement();
    6. QDomNode n = docElem.firstChild();
    7. n = n.nextSibling();
    8. QDomElement e = n.toElement();
    9. QByteArray screenshot = e // to QByteArray. what should be here ?
    10. chatGui->screenshot(screenshot);
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by probine; 2nd May 2006 at 15:30. Reason: add code

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Convert QPixmap to QByteArray ?

    I guess you must do something like that
    Qt Code:
    1. QByteArray screenshot;
    2. screenshot.setRawData(e.text().data(),e.text().lenght());
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: Convert QPixmap to QByteArray ?

    How to convert QPixmap to QByteArray ? I encountered the problem now.

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Convert QPixmap to QByteArray ?

    You have the answer in second post.

Similar Threads

  1. how to convert an int to QByteArray
    By babu198649 in forum Qt Programming
    Replies: 12
    Last Post: 19th September 2014, 09:47
  2. convert QString to QByteArray
    By morgana in forum Qt Programming
    Replies: 5
    Last Post: 2nd March 2011, 13:33
  3. How can we convert video stream to QPixmap?
    By learning_qt in forum Qt Programming
    Replies: 1
    Last Post: 9th September 2008, 23:44
  4. Replies: 4
    Last Post: 28th August 2008, 13:13
  5. Convert from QByteArray to String ?
    By probine in forum Newbie
    Replies: 3
    Last Post: 25th March 2006, 15:49

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.