Here’s one way to create an image of a view. There may be a better way, but this certainly works. If you do know of a better way, then please comment.
Self is an NSView.
NSRect boxrect = self.bounds; NSData* pdf = [self dataWithPDFInsideRect:boxrect]; NSImage* viewSnapshot = [[NSImage alloc] initWithData:pdf];
You can then go on to make a translucent version of the image. This is useful for drag & drop.
NSImage* dragImage = [[NSImage alloc] initWithSize:viewSnapshot.size]; [dragImage lockFocus]; [viewSnapshot dissolveToPoint:NSZeroPoint fraction:0.85]; [dragImage unlockFocus];
Note that I’m using garbage collection here. Alter as necessary if you need to manage memory.
On Apple’s site there’s a demo of how to do screenshots of windows or the whole screen. It’s called SonOfGrab and it’s Leopard only. I’ve not yet tried it myself.
Posted by stevewaddicor