Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IconRef and NSImageRep



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >IconRef and NSImageRep (From: David Catmull <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.