6

我在处理视网膜显示器时遇到了问题。NSImage 大小是正确的,但是如果我从中创建 NSBitmapImageRep 并将其写入文件,我会得到图像女巫的大小是原始图像的两倍。当我在非视网膜显示器上使用它时没有这样的问题。

  • 我从文件(1920x1080)创建 NSImage
  • 我在上面画了一些图
  • 我从带有图纸的图像创建 NSBitmapImageRep
  • 我把它写到文件中
  • 我得到 3840x2160 尺寸的图像

是什么原因造成的?


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];

如果我打开图像并保存而不进行编辑,我会得到正确的尺寸图像

NSImage *imageFromFile = [[NSImage alloc] initWithContentsOfURL:fileURL];
NSBitmapImageRep *newRepresentation = [[NSBitmapImageRep imageRepsWithData:[imageFromFile TIFFRepresentation]];
NSData *savingData = [newRepresentation representationUsingType: NSPNGFileType properties: nil];
[savingData writeToFile:desiredFileLocationAndName atomically:no];
4

1 回答 1

1

图像的位图表示以像素为单位。它的大小原来的两倍。NSImage 以点为单位为您提供大小,在视网膜设备上每点测量 2 个像素。它给你的东西没有错。

于 2013-03-19T13:25:39.130 回答