Re: Rendering an NSControl into a NSImage?
Re: Rendering an NSControl into a NSImage?
- Subject: Re: Rendering an NSControl into a NSImage?
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 1 Apr 2003 15:49:46 -0800
On Tuesday, April 1, 2003, at 03:33 PM, Mark Alldritt wrote:
This code does not compile because rep is undefined. I changed it to
the
following -- I'm not sure if this is what you intended:
[snip]
Whoops!
Umm, no, that's not what I had in mind. (Mail.app is a lousy code
editor ;-)
Try:
- (NSImage *) snapshotFromRect:(NSRect) sourceRect;
/*"This method creates a new image from a portion of the receiving
view. The image is returned autoreleased."*/
{
NSImage
*snapshot = [[NSImage alloc] initWithSize:sourceRect.size];
[snapshot lockFocus];
[[NSColor clearColor] set]; // these two lines may be unnecessary.
NSRectFill(sourceRect);
[self drawRect:sourceRect];
[snapshot unlockFocus];
return [snapshot autorelease]; // balance the +alloc call..
}
the resultant image should end up containing one NSCachedImageRep. If
you see strangeness that looks like coordinates getting munged, you
might need to resort to using CG functions to make the current CG
transform equivalent to that of the reciever.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.