PDA

View Full Version : QPixmap from QByteArray.



munna
7th July 2006, 15:02
Hi,

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

str = "TU0AKgAAAyiAP+BQOCQWDQeEQmFQuGQ2HQ+IRGJROKRWLReMRm NRuOR2PR+QSGRSOPPyTOZ1OxjM1pLZfsVtuBxySaTWHvF5vVkN BqqlZrlTrFbqqfthvOKbUmlQN4PN6L1jMugrep1NZLtguR0uul 12RvZ8PhhstoVWhWZbr5jsywPivW+PzFxqhZUCz3ehz9st+Z3C/Rp6vd8MFks60Whis1ovd8vm/4+Lul2O5YrpgYehMBkM2mvTIZ+LOJzOm0ZVgM5qtmcvbQa1+69 6PZ76vXv2Eu14PJmNNsNNtN7JO7a0yncF2u9423Wx+TPx0ZNlN Fqrthslar5iddiLxispmtRsc93Pl9PuB7Xyvt3vJ575vVBlrVe sOrsFZLxgy5i2NoN1xnMxjHOWiLVmWaRrFcW5eroXDMKooS6Fy V5cF8zRmmubpwG4cJyJWaT6wjB0HKIXMLHUdx4QGhbcHk7hlRE vEYQeW8GQZGUbxioTtHIdB1uHFTVl4"

I want to get the image from this string




QPixmap pm;
pm.loadFromData(QByteArray::fromBase64(str));



But this is not working.

Can someone please help me?

Thanks a lot.

jacek
7th July 2006, 15:14
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?

munna
8th July 2006, 07:11
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.

munna
8th July 2006, 07:21
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.

jacek
8th July 2006, 15:03
I was able to decode that string with QByteArray::fromBase64() without any problems.


#include <QCoreApplication>
#include <QByteArray>
#include <QFile>

const char data[] = "TU...A=";

int main( int argc, char **argv )
{
QCoreApplication app( argc, argv );

QFile f( "out.tiff" );
f.open( QIODevice::WriteOnly );
f.write( QByteArray::fromBase64( data ) );
}

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

munna
8th July 2006, 15:17
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"




QString v = QString(QByteArray::fromBase64( data ));



Thanks a lot for your time.
Thanks

jacek
8th July 2006, 15:37
How did you find that this is a TIFF data?
`man file`


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