Re: Rendering an NSControl into a NSImage?
Re: Rendering an NSControl into a NSImage?
- Subject: Re: Rendering an NSControl into a NSImage?
- From: Mark Alldritt <email@hidden>
- Date: Tue, 01 Apr 2003 15:33:41 -0800
>
NSImage
>
*snapshot = [[NSImage alloc] initWithSize:sourceRect.size];
>
>
[snapshot lockFocus];
>
>
[[NSColor clearColor] set]; // these two lines may be unnecessary.
>
NSRectFill(sourceRect);
>
>
[self drawRect:sourceRect];
>
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:sourceRect];
>
[snapshot unlockFocus];
>
return [snapshot autorelease]; // balance the +alloc call..
Thanks.
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:
NSRect sourceRect = [self frame];
NSImage *snapshot = [[NSImage alloc] initWithSize:sourceRect.size];
NSBitmapImageRep*rep;
[snapshot lockFocus];
[[NSColor clearColor] set]; // these two lines may be unnecessary.
NSRectFill(sourceRect);
[self drawRect:sourceRect];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:sourceRect];
[snapshot unlockFocus];
[snapshot addRepresentation:rep];
return [snapshot autorelease]; // balance the +alloc call..
With this code, I'm back to where I started: the button is clipped so the
round ends are missing and the title string is drawn across the bottom of
the button.
Cheers
-Mark
---------------------------------------------------------------------
Mark Alldritt Late Night Software Ltd.
Phone: 250-380-1725 333 Moss Street
FAX: 250-383-3204 Victoria, B.C.
WEB:
http://www.latenightsw.com/ CANADA V8V-4M9
_______________________________________________
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.