How to write out a Cocoa file type icon as a 16x16 PNG file? -
How can you write a 16x16 PNG file for a file type icon in Cocoa? I tried to do this with code like snippets before. Snippet worked with Mac OS X 10.5 on PPC machine, but now does not work on Mac OS X 10.6: PNG has written that instead of 16x16 it is 512x512 size.
NSImage * icon = [[NSWorkspace shared workspace] iconfile: NSFileTypeForHFSTypeCode (kGenericFolderIcon)]; [Set icon set: nsmcases (16.0.16.0)]; NSBitmapImageRep * bitmapRep = [NSBitmapImageRep imageRepWithData: [icon TIFF Representation]]; NSDTA * Data = [Bitmap Ripple Representation: User Type: NSPN FileType Properties: Zero]; [Write data file: @ "/ tmp / test page" atomic: no]; What do I understand from documentation on NSImage and NSImageRep , the fact that the above code was coincident earlier, as Set size: sets the "drawing size" of the image that does not necessarily match the "mail" of its representation (physical size). So what is the correct way to get the 16x16 size PNG file? In addition, the icon in Mac OS X can include a specially designed version for the 16x16 size, which is a small-sized version of the not "big" icon; How do you make sure that when someone is available, then this particular version is written in PNG file?
If you are certain that there are 16x16 version of the icon present in NSImage, you represent the representation ( - [NSImage representations] ) and choose what you are interested in size ( - [NSImageRep pixels wide] and pixels high ) . Then you can write representation on the disk. A better way would be to create 16x16 bitmap references, drag the image in that context and then save the reference material. This method also works if the original icon does not have 16x16 representation.
Comments
Post a Comment