Search code examples
objective-ccocoaimagensimage

NSImage acting weird


Why is this code setting artistImage to an image with 0 width and 0 height?

NSURL *artistImageURL = [NSURL URLWithString:@"http://userserve-ak.last.fm/serve/252/8581581.jpg"];
NSImage *artistImage = [[NSImage alloc] initWithContentsOfURL:artistImageURL];


Solution

  • NSImage does load this fine for me, but that particular image has corrupt metadata. Its resolution according to the exif data is 7.1999997999228071e-06 dpi.

    NSImage respects the DPI info in the file, so if you try to draw the image at its natural size, you'll get something 2520000070 pixels across.