Screenshot code for Tiger
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