• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Capture window content
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Capture window content
  • Next by Date: stringByReplacingOccurrencesOfString in Tiger
  • Previous by thread: Capture window content
  • Next by thread: stringByReplacingOccurrencesOfString in Tiger
  • Index(es):
    • Date
    • Thread