我正在尝试绘制并保存一个简单的图像,但它最终在 MBP RD 设备上保存了两倍大:
NSImage* image = [[NSImage alloc] initWithSize:size];
[image lockFocus];
[[NSColor blueColor] set];
NSRectFill(CGRectMake(0, 0, 100, 100));
[image unlockFocus];
// ... then save the image
// Cache the reduced image
NSData *imageData = [self TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
NSDictionary *imageProps = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];
imageData = [imageRep representationUsingType:NSPNGFileType properties:imageProps];
[imageData writeToFile:fileName atomically:NO];
// image is saved as 200 x 200 :(
我想要一个一致的尺寸,所以在所有设备上都是 100x100