Re: Capture window content
Re: Capture window content
- Subject: Re: Capture window content
- From: Lorenzo <email@hidden>
- Date: Sun, 27 Jan 2008 18:51:52 +0100
Hi,
You should get an NSBitmapImageRep from the contentView of your window with
InitWithFocusedViewRect or with bitmapImageRepForCachingDisplayInRect
I paste here below the code I use for so long time.
NSView *contentView = [aWindow contentView];
[contentView lockFocus];
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
initWithFocusedViewRect:[contentView bounds]];
[contentView unlockFocus];
// This works on Tiger and Leopard, but not on Panther
// NSBitmapImageRep *rep = [contentView
bitmapImageRepForCachingDisplayInRect:[contentView bounds]];
// [contentView cacheDisplayInRect:imageRect toBitmapImageRep:rep];
// This works on Leopard, Tiger and Panther
if(rep){
NSData *imageData = [rep
TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:15.0];
// To write the image to the disk, use
// [imageData writeToFile:@"/YourFolder/Image.tiff" atomically:YES];
// To create an NSImage, use
NSImage *image = [[NSImage alloc] initWithData:imageData];
[rep release]; rep = nil;
}
Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
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