reading image from plist with Jpeg photo data

Discussion in 'Mac Programming' started by hiddenpremise, Apr 22, 2011.

  1. hiddenpremise, Apr 22, 2011
    Last edited: Apr 22, 2011

    macrumors regular


    Jul 25, 2008
    Somewhere between my imagination and reality
    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
  2. Moderator emeritus


    Jun 15, 2000
    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?
  3. macrumors 68000


    Aug 17, 2009
    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:).
  4. chown33, Apr 23, 2011
    Last edited: Apr 23, 2011

    macrumors 604

    Aug 9, 2009
    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).

    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.
  5. thread starter macrumors regular


    Jul 25, 2008
    Somewhere between my imagination and reality
    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!
  6. Moderator


    Staff Member

    Aug 16, 2005
    New England
    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?


Share This Page