I am trying to display the icons of the Trash can in my app, both empty and full. I've tried several methods to get the icons, but each time the size is 32x32. Do you know a way to get a full size image?
-
2FYI, you cannot use Apple's images without permission. If you need a trash icon, checkout http://www.iconfinder.com/ – Dave DeLong Jun 01 '11 at 19:26
4 Answers
I assume that you’re getting the trash icon through NSWorkspace, using the kTrashIcon
constant from IconsCore.h (if you’re not, this is :
NSImage* image = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kTrashIcon)];
…this NSImage contains representations in a number of different sizes. If you want the biggest one, just iterate through the available representations to find it:
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];
…On my computer, this results in an NSImage set to 512x512.

- 50,525
- 12
- 70
- 98
-
+1, Forgot all about that—much better than hard-coding paths. There's also `kFullTrashIcon` as well. – NSGod Jun 01 '11 at 22:30
If you're creating an image from the following file, then realize that 32px x 32px is simply the default size:
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/TrashIcon.icns
Just resize it to the size you'd like:
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)];
When you do so, the NSImage
will automatically choose the appropriate image rep from those that are available. For example, logging the image shows the following description:
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"
)
Most images that represent file icons such as those returned by NSWorkspace
will have many sizes available, though 32 x 32 is the default size.

- 22,699
- 3
- 58
- 66
/System/Library/CoreServices/Dock.app/Contents/Resources/trashfull.png /System/Library/CoreServices/Dock.app/Contents/Resources/trashempty.png
It's 128x128 icon

- 617
- 3
- 10