Skip navigation.
 
mlPlotting icons into NSImage
FROM : Daniel Dalquen
DATE : Mon Apr 30 18:55:52 2007

Hello everybody!

I am running into problems when plotting an IconRef into an NSImage. 
Here is the piece of code I am using:

         IconRef ref;
         err = GetIconRefFromFileInfo (&fsref, fname.length, fname.unicode,
               kIconServicesCatalogInfoMask, &catinfo, 
kIconServicesNormalUsageFlag, &ref, &label);
                  
         if (err == noErr)
         {
             CGRect myRect = CGRectMake(0,0,128,128);
             NSImage* image = [[NSImage alloc] initWithSize:NSMakeSize
(128,128)];
             [image lockFocus];
             PlotIconRefInContext((CGContextRef)[[NSGraphicsContext 
currentContext]
                   
graphicsPort],&myRect,kAlignNone,kTransformNone,NULL,kPlotIconRefNormalF
lags,ref);
             [image unlockFocus];
             NSData * imageData = [image TIFFRepresentation];
           
             [imageData writeToFile:@"/Users/daniel/Desktop/myicon.tif" 
atomically:YES];

When I open myicon.tif in Preview, the icon is on top of a black 
background. I thought it might be the alpha channel, but then Preview 
should be able to deal with transparency... What is it that goes wrong?

Cheers,
Daniel

Related mailsAuthorDate
mlPlotting icons into NSImage Daniel Dalquen Apr 30, 18:55
mlRe: Plotting icons into NSImage Uli Kusterer May 2, 21:54
mlRe: Plotting icons into NSImage Daniel Dalquen May 2, 23:06
mlRe: Plotting icons into NSImage Matt Neuburg May 4, 20:04