Creating an NSImage of a View and its Contents
Creating an NSImage of a View and its Contents
- Subject: Creating an NSImage of a View and its Contents
- From: Stephen Blinkhorn <email@hidden>
- Date: Tue, 21 Dec 2010 14:11:22 -0600
Hi all,
I'm trying to capture a view and its contents as an NSImage which I
can subsequently draw in the view. The idea is that I'm trying to
'freeze' the view's content (custom sliders, buttons, menus etc) and
present this image in the view.
I'm getting mixed results when attempting to render to a CFLayerRef
e.g.:
NSRect viewRect = [self bounds];
[self lockFocus];
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc]
initWithFocusedViewRect:viewRect];
[self unlockFocus];
NSImage* image = [[NSImage alloc] initWithSize:viewRect.size];
[image addRepresentation:rep];
[image drawAtPoint:NSZeroPoint fromRect:viewRect
operation:NSCompositeSourceOver fraction:1.0];
[image release];
[rep release];
Nothing appears to be drawn in the layer. Is there a better approach
that I'm missing?
Thanks,
Stephen
_______________________________________________
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