PDA

View Full Version : reading image from plist with Jpeg photo data




hiddenpremise
Apr 22, 2011, 09:59 PM
Hi, I've got a plist file with jpeg photo data in it. I need to get that photo out. I can read the plist file into an NSDictionary and can access the object at the key "jpegphoto". The problem is that the object returned is an NSCFArray that I have no idea how to work with. I can print it and I see a nice stream of octets come out, but that's all I know how to do. How do I get this NSCFArray into NSData or a byte array?

The CFArray when passed to NSLog like so
NSLog(@"%@", [data_dictionary objectForKey:@"jpegphoto"]);
Spits out hundreds of line similar to
5ed15ee6 df44b2ff 00899699 0dd23b58 dccdcadc 6c8d04e1 8b3e1940 af76953e 7c0e1b56
I know that it is a CFArray b/c I did
NSLog(@"%@", NSStringFromClass([[data_dictionary objectForKey:@"jpegphoto"] class]));
And got back
NSCFArray
Thanks



kainjow
Apr 22, 2011, 11:43 PM
Where is this plist coming from? If the "jpegphoto" was an NSData that'd be pretty obvious how to load it, but since it's an array it's unclear what the array is holding.

Can you loop through the array and print out the class name of each of its objects?

Sydde
Apr 22, 2011, 11:49 PM
From what you are showing, it looks like an array of either NSNumbers or NSStrings. You might try concatenating the values in the array together to form a block of data that NSImage would be able to convert.

If it is NSNumbers, you should be able to just walk a pointer through a data block for each number. If it is hex-encoded strings, you would have to use a NSScanner to convert them to numbers (-scanHexInt:).

chown33
Apr 23, 2011, 11:36 AM
Spits out hundreds of line similar to
5ed15ee6 df44b2ff 00899699 0dd23b58 dccdcadc 6c8d04e1 8b3e1940 af76953e 7c0e1b56

If that's the start of the data, I have no idea what it represents. It's not a JFIF (JPEG File Interchange Format, aka JPEG file).
http://en.wikipedia.org/wiki/JPEG_File_Interchange_Format

If that isn't the start of the data, then post the starting line of data.

How do you know it's JPEG data? If you told us where the data came from, we might have better suggestions.

hiddenpremise
Apr 24, 2011, 12:44 PM
I know it is jpeg data because the key in the plist is called "jpegphoto". And what I posted is just the beginning. I shortened it b/c that actual data is very long. Thanks!

balamw
Apr 24, 2011, 02:18 PM
I know it is jpeg data because the key in the plist is called "jpegphoto". And what I posted is just the beginning. I shortened it b/c that actual data is very long. Thanks!

It could still be JPEG data, but without the JFIF/EXIF headers or with the headers later in the stream. If so you might have trouble interpreting it without necessarily knowing the image's dimensions, etc...

Do you find 0xFFE0????4A46 anywhere in the stream?

B