hoc*_*man 5 macos objective-c nsimage retina-display
我在视网膜显示器上工作时遇到了问题.NSImage大小是正确的,但如果我从它创建NSBitmapImageRep并将其写入文件我得到的图像女巫的大小是原始图像的两倍大.当我在非视网膜显示器上使用它时没有这样的问题.
可能导致什么?
NSImage *originalImage = [[NSImage alloc] initWithContentsOfURL:fileUrl];
NSImage *editedImage = [[NSImage alloc] initWithSize:originalImage.size];
[editedImage lockFocus];
//I draw here NSBezierPaths
[editedImage unlockFocus];
NSBitmapImageRep *savingRep = [NSBitmapImageRep imageRepsWithData:[editedImage TIFFRepresentation]];
NSData *savingData = [savingRep representationUsingType: NSPNGFileType properties: nil];
[savingData writeToFile:desiredFileLocationAndName atomically:no];
Run Code Online (Sandbox Code Playgroud)
如果我打开图像并保存而不进行编辑,我会得到正确的尺寸图像
NSImage *imageFromFile = [[NSImage alloc] initWithContentsOfURL:fileURL];
NSBitmapImageRep *newRepresentation = [[NSBitmapImageRep imageRepsWithData:[imageFromFile TIFFRepresentation]];
NSData *savingData = [newRepresentation representationUsingType: NSPNGFileType properties: nil];
[savingData writeToFile:desiredFileLocationAndName atomically:no];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
688 次 |
| 最近记录: |