I have two PNGs in a Mac project. Normal and @ 2x. Xcode combines them into one TIFF with @ 2x at index 0 and @ 1x at index 1.
What is the proposed approach for obtaining the corresponding image as a version of CGImageRef (for use with quartz) for the current display scale?
I can get the image manually through CGImageSource:
NSBundle *mainBundle = [NSBundle mainBundle]; NSURL *URL = [mainBundle URLForResource:@"Canvas-Bkgd-Tile" withExtension:@"tiff"]; CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)(URL), NULL); _patternImage = CGImageSourceCreateImageAtIndex(source, 1, NULL);
I also found this to work, but I'm not sure if this will return the Retina version on the Retina display:
NSImage *patternImage = [NSImage imageNamed:@"Canvas-Bkgd-Tile.tiff"]; _patternImage = [patternImage CGImageForProposedRect:NULL context:nil hints:nil]; CGImageRetain(_patternImage);
A valid answer to this question either gives a decision on how to get a CGImage from a combined TIFF with multiple permissions, or explains why the second approach works. Or what changes are needed.
source share