Re: IconRef and NSImageRep
Re: IconRef and NSImageRep
- Subject: Re: IconRef and NSImageRep
- From: Constantine <email@hidden>
- Date: Fri, 21 Dec 2007 10:43:38 +0800
The following code may help you:
{
NSImage * image = nil;
NSImage * outImage = nil;
NSData * imageRep = nil;
NSSize imageSize = NSMakeSize(48.0,48.0);
outImage = [[NSImage alloc] initWithSize:imageSize];
image = [[[NSWorkspace sharedWorkspace] iconForFile:@"/Applications/
Safari.app"] retain];
[image setScalesWhenResized:YES];
[outImage lockFocus];
[image setSize:imageSize];
[[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
[image compositeToPoint:NSZeroPoint operation: NSCompositeSourceOver];
[outImage unlockFocus];
[image release];
imageRep = [outImage TIFFRepresentation];
[outImage release];
}
Liu Qi
On Dec 20, 2007, at 3:14 AM, David Catmull wrote:
I'm trying to make an NSImageRep subclass that draws IconRefs, but
it isn't working - nothing appears on the screen.
I get the IconRef by calling GetIconRef
(kOnSystemDisk,kSystemIconsCreator,kGenericFolderIcon,&iconRef),
which succeeds by all appearances.
Then I have this method in my NSImageRep subclass:
-(void)draw
{
NSSize mySize = [self size];
CGRect drawRect = CGRectMake(0,0,mySize.width,mySize.height);
PlotIconRefInContext((CGContextRef)[[NSGraphicsContext
currentContext] graphicsPort],
&drawRect,kAlignNone,kTransformNone,NULL,kPlotIconRefNormalFlags,iconR
ef);
}
In the debugger, mySize and drawRect have the expected values
(0,0,48,48), but nothing draws. This is in a table cell, and other
cells that use images loaded from files appear correctly.
Originally I used [NSWorkspace iconForFileType:], but the resulting
image didn't draw well at 48x48. It appeared to be scaled down from
the 128x128 image with no smoothing applied. I tried it with and
without using setScalesWhenResized.
So, what could I be doing wrong in my NSImageRep? Should I go back
to the NSWorkspace approach and try something different?
Thanks,
--
David Catmull
email@hidden
http://www.uncommonplace.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden