Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Capture window content



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.