NSImage imageNamed:对于 Mac Mini 返回小图标而不是高分辨率
当使用 NSImage 的 imageNamed: 方法获取当前计算机的图标时,如果我在 Mac Mini 上运行,则会得到低分辨率图像。如果我在 MacBook 上运行相同的代码,那么我会得到一个像我期望的那样的高分辨率图标。
我的代码如下:
NSImage *image;
image = [NSImage imageNamed:@"NSComputer"];
[image setSize: NSMakeSize(512,512)];
NSData * tiffData = [image TIFFRepresentation];
NSBitmapImageRep *bitmap = [NSBitmapImageRep imageRepWithData:tiffData];
data = [bitmap representationUsingType:NSPNGFileType properties:nil];
mime = @"image/png";
当我在 MacBook 上运行该代码时,一切运行良好,并且我获得了计算机的 512x512 图标。当我在 Mac Mini 上运行它时,我得到一个 32x32 的图标,该图标已放大到 512x512。
关于如何获得高分辨率版本有什么想法吗?
When using NSImage
's imageNamed:
method to get the icon for the current computer, if I'm running on a Mac Mini, then I get a low resolution image. If I run the same code from my MacBook, then I get a high-res icon like I'd expect.
My code is as follows:
NSImage *image;
image = [NSImage imageNamed:@"NSComputer"];
[image setSize: NSMakeSize(512,512)];
NSData * tiffData = [image TIFFRepresentation];
NSBitmapImageRep *bitmap = [NSBitmapImageRep imageRepWithData:tiffData];
data = [bitmap representationUsingType:NSPNGFileType properties:nil];
mime = @"image/png";
When I run that on my MacBook, everything works great and I get a 512x512 icon of the my computer. When I run it on my Mac Mini, i get a 32x32 icon that's been upscaled to 512x512.
Any ideas on how I can get the high-res version?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信该图像来自
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/
Mac mini 图标名为
com.apple.macmini.icns
。您可能想检查该文件在您的计算机上是否包含 512x512 图标(在我的计算机上,运行 Snow Leopard 时确实如此)。出于调试目的,您还应该将
-representations
的输出发送到NSLog
来验证图标是否有 512x512 版本。编辑:
10.6 AppKit 发行说明 有相当多的内容NSImage 和 CGImage 之间的更新关系。
在 Snow Leopard 上,您可以通过转换为 CGImageRef 来获取全分辨率图像:
从那里,您可以从 CGImageRef 创建新的 NSImage,或使用 CGImageDestination* API 写入 png 文件。
I believe that image comes from
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/
The Mac mini icon is named
com.apple.macmini.icns
. You may want to check if that file contains a 512x512 icon on your machine (it does on mine, running Snow Leopard)'For debugging purposes, you should also send the output of
-representations
toNSLog
to verify that the icon does or does not have a 512x512 version.Edit:
The 10.6 AppKit Release Notes has quite a bit on the updated relationship between NSImage and CGImage.
On Snow Leopard, you can get the full resolution image by converting to a CGImageRef:
From there, you can create a new NSImage from the CGImageRef, or use the CGImageDestination* APIs to write a png file.