我正在尝试在我的应用中显示垃圾箱的图标,包括空和满。我已经尝试了几种方法来获取图标,但每次大小为32x32。你知道一种获得全尺寸图像的方法吗?
答案 0 :(得分:6)
我假设您使用来自IconsCore.h的kTrashIcon
常量通过NSWorkspace获取垃圾桶图标(如果您不是,请执行以下操作:
NSImage* image = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kTrashIcon)];
...此NSImage包含多种不同大小的表示。如果你想要最大的一个,只需遍历可用的表示来找到它:
NSEnumerator* representationEnumerator = [[image representations] objectEnumerator];
NSSize biggestSize = NSMakeSize(0, 0);
NSSize size;
while ((size = [(NSImageRep*)[representationEnumerator nextObject] size]).width) {
if (size.width > biggestSize.width) {
biggestSize = size;
}
}
[image setSize:biggestSize];
...在我的电脑上,这会导致NSImage设置为512x512。
答案 1 :(得分:2)
如果您要从以下文件创建图像,请认识到32px x 32px只是默认大小:
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/TrashIcon.icns
只需将其调整为您想要的尺寸:
NSString *path = @"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/TrashIcon.icns";
NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
[image setSize:NSMakeSize(512.0, 512.0)];
执行此操作时,NSImage
将自动从可用的图像代表中选择适当的图像代表。例如,记录图像显示以下描述:
image == NSImage 0x102e16bc0 Size={512, 512} Reps=(
"NSBitmapImageRep 0x102e1f650 Size={512, 512} ColorSpace=(not yet loaded)
BPS=8 BPP=(not yet loaded) Pixels=512x512 Alpha=YES Planar=NO
Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",
"NSBitmapImageRep 0x102e24c80 Size={256, 256} ColorSpace=(not yet loaded)
BPS=8 BPP=(not yet loaded) Pixels=256x256 Alpha=YES Planar=NO
Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",
"NSBitmapImageRep 0x102e25540 Size={128, 128} ColorSpace=(not yet loaded)
BPS=8 BPP=(not yet loaded) Pixels=128x128 Alpha=YES Planar=NO
Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",
"NSBitmapImageRep 0x102e25e30 Size={32, 32} ColorSpace=(not yet loaded)
BPS=8 BPP=(not yet loaded) Pixels=32x32 Alpha=YES Planar=NO
Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",
"NSBitmapImageRep 0x102e26720 Size={16, 16} ColorSpace=(not yet loaded)
BPS=8 BPP=(not yet loaded) Pixels=16x16 Alpha=YES Planar=NO
Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0"
)
大多数代表文件图标的图片(例如NSWorkspace
返回的图片)都有许多尺寸,但32 x 32是默认尺寸。
答案 2 :(得分:1)
/System/Library/CoreServices/Dock.app/Contents/Resources/trashfull.png /System/Library/CoreServices/Dock.app/Contents/Resources/trashempty.png
这是128x128图标
答案 3 :(得分:-4)
在Google图片上搜索“Mac OS Trash”