开发者

NSImage imageNamed: for Mac Mini returns small icon instead of high-res

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 b开发者_如何学JAVAeen upscaled to 512x512.

Any ideas on how I can get the high-res version?


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 to NSLog 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:

NSImage* image = [NSImage imageNamed:NSImageNameComputer];
NSRect imageRect = NSMakeRect(0, 0, 512, 512);
CGImageRef cgImage = [image CGImageForProposedRect:&imageRect context:nil hints:nil];

From there, you can create a new NSImage from the CGImageRef, or use the CGImageDestination* APIs to write a png file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜