Get full size basket icons

I am trying to display trash icons in my application, both empty and full. I tried several methods for getting the icons, but each time the size is 32x32. Do you know a way to get a full size image?

+3
source share
4 answers

I assume that you get the trash icon through NSWorkspace using the constant kTrashIconfrom IconsCore.h (if you are not:

NSImage* image = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kTrashIcon)];

... this NSImage contains views in different sizes. If you want the largest, just go through the available views 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 leads to the installation of NSImage in 512x512.

+5
source

, , 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

/System/Library/CoreServices/Dock.app/Contents/Resources/trashfull.png /System/Library/CoreServices/Dock.app/Contents/Resources/trashempty.png

128x128

+1

" Mac OS" Google

-4

All Articles