• 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
Screenshot code for Tiger
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Screenshot code for Tiger


  • Subject: Screenshot code for Tiger
  • From: Nir Soffer <email@hidden>
  • Date: Sun, 23 Apr 2006 17:51:24 +0300

I searched for screenshot example code, and found few solutions, and its not clear which is the way to go.

First I found this code:

NSView *view = [window contentView];
[view lockFocus];
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[view bounds]];
[view unlockFocus];


But various comments suggest it does not work on Tiger any more. Anyone knows why?

Then there is Apple glGrab example code
http://developer.apple.com/samplecode/Sample_Code/Archive/Graphics/ glGrab.htm. The file was removed from Apple site - anyone knows why?


Then there is this code, that appear to be copied from glGrab.c:
http://www.cocoabuilder.com/archive/message/cocoa/2005/8/13/144256.

Then in http://www.cocoadev.com/index.pl?ScreenShotCode, there is code base on glGrab by http://www.cocoadev.com/index.pl?MikeAsh.

Then there is this code using Carbon in http://www.cocoadev.com/index.pl?ScreenShotCode, by http://www.cocoadev.com/index.pl?RyanBates:

+ (NSImage *)imageWithScreenShotInRect:(NSRect)cocoaRect
{
        PicHandle picHandle;
        GDHandle mainDevice;
        Rect rect;
        NSImage *image;
        NSImageRep *imageRep;

// Convert NSRect to Rect
SetRect(&rect, NSMinX(cocoaRect), NSMinY(cocoaRect), NSMaxX(cocoaRect), NSMaxY(cocoaRect));


// Get the main screen. I may want to add support for multiple screens later
mainDevice = GetMainDevice();


// Capture the screen into the PicHandle.
picHandle = OpenPicture(&rect);
CopyBits((BitMap *)*(**mainDevice).gdPMap, (BitMap *)*(**mainDevice).gdPMap,
&rect, &rect, srcCopy, 0l);
ClosePicture();


// Convert the PicHandle into an NSImage
// First lock the PicHandle so it doesn't move in memory while we copy
HLock((Handle)picHandle);
imageRep = [NSPICTImageRep imageRepWithData:[NSData dataWithBytes:(*picHandle)
length:GetHandleSize((Handle)picHandle)]];
HUnlock((Handle)picHandle);


        // We can release the PicHandle now that we're done with it
        KillPicture(picHandle);

// Create an image with the representation
image = [[[NSImage alloc] initWithSize:[imageRep size]] autorelease];
[image addRepresentation:imageRep];


        return image;
}

Finally, there is this code from sticksoftwate: http://www.sticksoftware.com/developer/Screensnap.m.txt

Maybe someone can clear the mess and explain which is the recommended and tested way to have a screenshot on Tiger?


Best Regards,

Nir Soffer

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Screenshot code for Tiger
      • From: "Dmitry Savenok" <email@hidden>
  • Prev by Date: Re: Superimpose a NSTextField over NSImageView?
  • Next by Date: Re: Weird bug with selection in Textview with custom textcontainer [solved]
  • Previous by thread: Re: Superimpose a NSTextField over NSImageView?
  • Next by thread: Re: Screenshot code for Tiger
  • Index(es):
    • Date
    • Thread