FSA21
FSA21

Reputation: 59

IOS 7 - Unable to read/load an image

I am puzzled here.

    UIImage *image = [UIImage imageNamed:@"search.png"];
    NSData *data = UIImagePNGRepresentation(image);
    NSLog(@"%d", [data length]);

what it read: 859 bytes

actual file: 244kb

So I try to see what DID get loaded:

    NSString *byteArray  = [data base64Encoding];

And decode this b64 to a binary, check it in an image viewer, its 1/4th of the picture. What is also weird is that a few lines later another .png gets imported in the same manner and that .png works fine.

Resources:

The image I am trying to load: https://i.sstatic.net/XiUyS.png

The result of the import: https://i.sstatic.net/ebgbq.png

The image that does work: https://i.sstatic.net/pSyS2.png

What am I missing?

Upvotes: 0

Views: 111

Answers (1)

mattt
mattt

Reputation: 19544

A few hundred bytes into the PNG file, it starts to embed 200kb of RDF data for no apparent reason (using Photoshop "Save..." instead of "Save for Web...", perhaps?):

<?xpacket begin="Ôªø" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.5-c021 79.155772, 2014/01/13-19:44:00        ">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
...

I have no idea if this is related to the described behavior, but it's certainly disconcerting. Assuming this is for UI in an iOS app, I'd start by just re-encoding your image to strip all of this away.

Upvotes: 1

Related Questions