Skip navigation.
 
mlRe: Capture window content
FROM : Lorenzo
DATE : Sun Jan 27 18:51:52 2008

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_removed>

Related mailsAuthorDate
mlRe: Capture window content Lorenzo Jan 27, 18:51
mlCapture window content Walter Yetta Jan 28, 02:36