Re: Rendering an NSControl into a NSImage?
Re: Rendering an NSControl into a NSImage?
- Subject: Re: Rendering an NSControl into a NSImage?
- From: "Mark's Studio" <email@hidden>
- Date: Wed, 2 Apr 2003 12:16:08 +0200
Maybe this could help, i use this to make a dragging image.
- (NSImage *) imageForRow:(int)aRow
{
NSRect rowRect = [[cellRects objectAtIndex:aRow] rectValue];
NSSize rowSize = rowRect.size;
NSImage *image=[[[NSImage allocWithZone:(NSZone *)[(NSObject *)self
zone]] initWithSize:rowSize] autorelease];
rowRect.origin= NSZeroPoint;
[image setFlipped:YES];
[image lockFocus];
[[cells objectAtIndex:aRow] drawWithFrame: rowRect inView: self];
[image unlockFocus];
return image;
}
On onsdag, apr 2, 2003, at 01:33 Europe/Copenhagen, Mark Alldritt wrote:
>
> 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.
>
>
Peter Mark
Mark's Recording Studio A/S
Lundeskovsvej 3 2900 Hellerup
Denmark
Tel: +45 35366078 Fax: +45 35366038
www.marks-studio.dk
email@hidden
_______________________________________________
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.