【问题标题】:Retina display problems when working with images处理图像时出现 Retina 显示问题
【发布时间】:2013-03-19 13:20:46
【问题描述】:

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

  • 我从文件 (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];

【问题讨论】:

标签: objective-c macos retina-display nsimage


【解决方案1】:

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

【讨论】:

  • 您有什么特别需要做的事情,新维度让您变得困难吗?
  • 问题是,当我打开图像并用我的应用程序处理它时,当我保存图像时,我得到的图像是以前的两倍,以像素为单位。而且我需要保持原始图像大小。
  • 您能否发布您在每个步骤中使用的代码。我认为您可以设置一个标志来避免该问题。
  • 我注意到不做任何绘图我得到正确的图像尺寸。
猜你喜欢
  • 1970-01-01
  • 2018-02-13
  • 2022-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多