Results 1 to 7 of 7

Thread: QPixmap from QByteArray.

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QPixmap from QByteArray.

    Hi,

    I have a string which represents an image and is base64 encoded.

    str = "TU0AKgAAAyiAP+BQOCQWDQeEQmFQuGQ2HQ+IRGJROKRWLReMR mNRuOR2PR+QSGRSOPPyTOZ1OxjM1pLZfsVtuBxySaTWHvF5vVk NBqqlZrlTrFbqqfthvOKbUmlQN4PN6L1jMugrep1NZLtguR0uu l12RvZ8PhhstoVWhWZbr5jsywPivW+PzFxqhZUCz3ehz9st+Z3 C/Rp6vd8MFks60Whis1ovd8vm/4+Lul2O5YrpgYehMBkM2mvTIZ+LOJzOm0ZVgM5qtmcvbQa1+69 6PZ76vXv2Eu14PJmNNsNNtN7JO7a0yncF2u9423Wx+TPx0ZNlN Fqrthslar5iddiLxispmtRsc93Pl9PuB7Xyvt3vJ575vVBlrVe sOrsFZLxgy5i2NoN1xnMxjHOWiLVmWaRrFcW5eroXDMKooS6Fy V5cF8zRmmubpwG4cJyJWaT6wjB0HKIXMLHUdx4QGhbcHk7hlRE vEYQeW8GQZGUbxioTtHIdB1uHFTVl4"

    I want to get the image from this string

    Qt Code:
    1. pm.loadFromData(QByteArray::fromBase64(str));
    To copy to clipboard, switch view to plain text mode 

    But this is not working.

    Can someone please help me?

    Thanks a lot.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap from QByteArray.

    Are you sure that this string is correct? It has wrong size. Maybe there's a '=' missing at the end? Is that a TIFF image?

  3. #3
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap from QByteArray.

    I did not paste the full string. Here is the full string.

    TU0AKgAAAyiAP+BQOCQWDQeEQmFQuGQ2HQ+IRGJROKRWLReMRm NRuOR2PR+QSGRSOPPyTOZ1OxjM
    1pLZfsVtuBxySaTWHvF5vVkNBqqlZrlTrFbqqfthvOKbUmlQN4 PN6L1jMugrep1NZLtguR0uul12
    RvZ8PhhstoVWhWZbr5jsywPivW+PzFxqhZUCz3ehz9st+Z3C/Rp6vd8MFks60Whis1ovd8vm/4+L
    ul2O5YrpgYehMBkM2mvTIZ+LOJzOm0ZVgM5qtmcvbQa1+696PZ 76vXv2Eu14PJmNNsNNtN7JO7a0
    yncF2u9423Wx+TPx0ZNlNFqrthslar5iddiLxispmtRsc93Pl9 PuB7Xyvt3vJ575vVBlrVesOrsF
    ZLxgy5i2NoN1xnMxjHOWiLVmWaRrFcW5eroXDMKooS6FyV5cF8 zRmmubpwG4cJyJWaT6wjB0HKIX
    MLHUdx4QGhbcHk7hlREvEYQeW8GQZGUbxioTtHIdB1uHFTVl4Y kXxzGccSNIsjyUvDCGdALlubAx
    rSXJEqypK8ilyYRjq1HzXs+2seHWWBcl/LErSTNM0TWtBcGCYzjnjFR/vEY5nGnG01TPPc9KFCZf
    NEdM5oGaBrm27U+TZPtFUYYhmGi9NBoEX61xJRNL0WtBWFsXij KRSSB0RTNR0ZTBbvqcrJVAgb61
    NV1SPkYZ1OPVaBNNV9S1JGRZl4YTxVqf9eGFXFiTVBJem8cZz2 BIRlTzXNoWLGcIu+bFgTsacyTN
    XVuWjWDsTjUBsG6cLqGTaV0LxBhkulJ8VRY3ZsRDbt02hEl4uU 1zXnAcpz21euAQgur+Vmd7ltW+
    GA29ha0F0YZkTmaRsG5eeGXpi9GSlOb1nnYWFXrTZeYLUDUGzj +MRknZq0jSSnHrNxjZPi0qvrE8
    U2AgVknOVZaF1mUzp8XL3ZwgramgaxtZ/btHGjfOiIKtsLaVRhbmAYtw6ehacHrqVFwZhxkSlQpt
    2qtRmUtReYHOdZ26yiLAnwaOJvqVZal2+5g5VLrYnu9Lauatrx Xi7RWwVvF445t3FcXxnG8dx/Ic
    jyXJ8pyvLIIgIAANAQAAAwAAAAEAMAAAAQEAAwAAAAEAMAAAAQ IAAwAAAAMAAAPKAQMAAwAAAAEA
    BQAAAQYAAwAAAAEAAgAAAREABAAAAAEAAAAIARUAAwAAAAEAAw AAARYABAAAAAEAAADjARcABAAA
    AAEAAAMgARoABQAAAAEAAAPQARsABQAAAAEAAAPYARwAAwAAAA EAAQAAASgAAwAAAAEAAgAAAAAA
    AAAIAAgACAAK/IAAACcQAAr8gAAAJxA=

    I checked the length, it is 1324 and while debugging it shows this value but QByteArray::fromBase64() returns "MM"

    Please help
    Thanks a lot.

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap from QByteArray.

    I also tried to decode this string with an external decoder and i got the same result - "MM". But this coded text is generated by mac address book (while exporting a vcf card).

    Also, KAddressBook is not able to import this. Is this, mac addressbook export bug? Can some one please confirm this?

    Thanks a lot.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap from QByteArray.

    I was able to decode that string with QByteArray::fromBase64() without any problems.

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QByteArray>
    3. #include <QFile>
    4.  
    5. const char data[] = "TU...A=";
    6.  
    7. int main( int argc, char **argv )
    8. {
    9. QCoreApplication app( argc, argv );
    10.  
    11. QFile f( "out.tiff" );
    12. f.open( QIODevice::WriteOnly );
    13. f.write( QByteArray::fromBase64( data ) );
    14. }
    To copy to clipboard, switch view to plain text mode 

    The only problem is that this is a TIFF file and Qt itself doesn't support TIFF.

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap from QByteArray.

    I have a few doubts.

    1. How did you find that this is a TIFF data?
    2. What should be the result of the following lines ? I am getting "MM"

    Qt Code:
    1. QString v = QString(QByteArray::fromBase64( data ));
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot for your time.
    Thanks

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap from QByteArray.

    Quote Originally Posted by munna
    How did you find that this is a TIFF data?
    `man file`

    Quote Originally Posted by munna
    What should be the result of the following lines ? I am getting "MM"
    I doesn't have much sense, since its binary data, not text. Anyway TIFF files start with MM or II.

    Here's a part of hex dump of the decoded file:

    0000000 4d4d 2a00 0000 2803 3f80 50e0 2438 0d16
    0000010 8407 6142 b850 3664 0f1d 4488 5162 a438
    0000020 2d56 8c17 6346 b851 76e4 1f3d 4890 5264
    0000030 f338 4cf2 75e6 183b d6cc d992 c57e b86d
    0000040 721c a449 1ed6 79f1 59bd 060d a5aa b966
    ...
    00003a0 d003 1b01 0500 0000 0100 0000 d803 1c01
    00003b0 0300 0000 0100 0100 0000 2801 0300 0000
    00003c0 0100 0200 0000 0000 0000 0800 0800 0800
    00003d0 0a00 80fc 0000 1027 0a00 80fc 0000 1027
    00003e0

Similar Threads

  1. Convert QPixmap to QByteArray ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2014, 08:23
  2. QPixmap -> HICON trouble.
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2006, 15:51
  3. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 16:24
  4. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 17:01
  5. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20: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.