Question

I have a question about the image output of a cocoa app. For the following code will create different sized images(2x or 1x depending on the display) in retina displays and non retina displays. But I want the output image is 225x300 in every situations.

NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
[image setScalesWhenResized:YES];
[image setSize:NSMakeSize(225, 300)];
[[image TIFFRepresentation]writeToURL:exportFileURL options:NSDataWritingAtomic error:&error];

My question is how to handle this correctly.

Était-ce utile?

La solution

Since you are writing the image from an NSView according to your comment, you'll need to properly support hi resolution retina displays. If the view is displayed on a retina display, you may want to adjust for scaling. See Apples Documentation on this. You will have to convertFrom/ToBacking accordingly.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top