Results 1 to 6 of 6

Thread: QImage to QByteArray

  1. #1
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QImage to QByteArray

    Hi,
    Is there any method to convert QImage to QByteArray???

    Thank You

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage to QByteArray

    this example was taken from assistant
    Qt Code:
    1. QImage image;
    2. QBuffer buffer(&ba);
    3. buffer.open(QIODevice::WriteOnly);
    4. image.save(&buffer, "PNG"); // writes image into ba in PNG format
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QImage to QByteArray

    Thank You..
    Is there any fuction to convert QImage to uchar* . Actually i used bits(), scanline() etc. Since it returns address, i cannot manipulate the data.
    Actually i need to copress the QImage row data using qCompress(). Can anyone help me out???

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage to QByteArray

    you can use this function
    Qt Code:
    1. QByteArray qCompress ( const QByteArray & data, int compressionLevel = -1 )
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage to QByteArray

    Qt Code:
    1. QByteArray compressed = qCompress(QByteArray((char*)image.bits(), image.numBytes()));
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. QByteArray compressed = qCompress(image.bits(), image.numBytes());
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage to QByteArray

    i have notice to compress QByteArray is faster & smal -> http://liblzf.plan9.de/
    i found this tip on KDE source...


    Qt Code:
    1. // Lossless compression using LZF algorithm, this is faster on modern CPU than
    2. // the original implementation in http://liblzf.plan9.de/
    3. // compression data on cache to not fill to match ram buffer
    4.  
    5. /* search on kde source : *xml */
    6. static int lzff_compress(const void* input, int length, void* output, int maxout)
    7. static int lzff_decompress(const void* input, int length, void* output, int maxout)
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 17:37
  2. Multiple QPainters on QImage
    By fire in forum Qt Programming
    Replies: 3
    Last Post: 14th August 2008, 14:10
  3. QImage loadFromData not run... XPDF data
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 24th April 2007, 12:51
  4. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 18:01
  5. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 21:23

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.