Re: Capturing the Content of a IKImageBrowserView
Re: Capturing the Content of a IKImageBrowserView
- Subject: Re: Capturing the Content of a IKImageBrowserView
- From: Alexander Griekspoor <email@hidden>
- Date: Thu, 10 Jan 2008 09:58:09 +0000
Hi Anthony,
I've recently become a fan of the CGWindow options (thanks to the
Jumpy samplecode of Lucas Newman), and wrote the following NSImage
category based on the Matt Gemmel's NSImage-Quicklook category). This
allows you to get an NSImage of your window exacty way it appears on
screen. It wouldn't be difficult to add a NSRect parameter for the
region of the window using an additional
CGImageCreateWithImageInRect(image, myRect)) step and passing in the
imagebrowsers frame, or you could in fact already pass that rect in
the CGWindowListCreateImage call.
Cheers,
Alex
+ (NSImage *)imageOfWindow: (NSInteger)windowNumber listOption:
(CGWindowListOption)listOption imageOption:
(CGWindowImageOption)imageOption tightFit: (BOOL)flag{
//call as [NSImage imageOfWindow: kCGNullWindowID listOption:
kCGWindowListOptionOnScreenOnly imageOption: kCGWindowImageDefault
tightFit: NO];
//or [NSImage imageOfWindow: [myWindow windowNumber] listOption:
kCGWindowListOptionIncludingWindow imageOption: kCGWindowImageDefault
tightFit: NO];
//or [NSImage imageOfWindow: [myWindow windowNumber] listOption:
kCGWindowListOptionIncludingWindow imageOption:
kCGWindowImageBoundsIgnoreFraming tightFit: YES];
//kCGWindowImageDefault = 0, /* Default behavior: If a rect of
CGRectNull is used bounds computation includes the framing effects,
such as a shadow. */
//kCGWindowImageBoundsIgnoreFraming = (1 << 0), /* If a rect of
CGRectNull is used, ignore framing effects for bounds computation */
//kCGWindowImageShouldBeOpaque = (1 << 1), /* The captured image
should be opaque. Empty areas are white */
//kCGWindowImageOnlyShadows = (1 << 2)
//kCGWindowListOptionAll or kCGWindowListOptionOnScreenOnly /* Use
all windows that are on screen in this user session. The windowID
should be kCGNullWindowID. */
//kCGWindowListOptionOnScreenAboveWindow /* Use all on-screen
windows above the specified window ordered from front to back. The
windowID should be the window number, as from [myWindow windowNumber].
//kCGWindowListOptionOnScreenBelowWindow /* Use all on-screen
windows below the specified window ordered from front to back. The
windowID should be the window number, as from [myWindow windowNumber].
//kCGWindowListOptionIncludingWindow /* Use only the specified
window to construct the image. The windowID should be the window
number, as from [myWindow windowNumber].
//(kCGWindowListOptionOnScreenAboveWindow |
kCGWindowListOptionIncludingWindow) /* Use all on-screen windows
including and above the specified window ordered from front to back.
The windowID should be the window number, as from [myWindow
windowNumber].
//(kCGWindowListOptionOnScreenBelowWindow |
kCGWindowListOptionIncludingWindow) /* Use all on-screen windows
including and below the specified window ordered from front to back.
The windowID should be the window number, as from [myWindow
windowNumber].
CGImageRef ref = CGWindowListCreateImage((flag ? CGRectNull :
CGRectInfinite), listOption, windowNumber, kCGWindowImageDefault);
if (ref != NULL) {
// Take advantage of NSBitmapImageRep's -initWithCGImage:
initializer, new in Leopard,
// which is a lot more efficient than copying pixel data into
a brand new NSImage.
// Thanks to Troy Stephens @ Apple for pointing this new
method out to me.
NSBitmapImageRep *bitmapImageRep = [[NSBitmapImageRep alloc]
initWithCGImage:ref];
NSImage *newImage = nil;
if (bitmapImageRep) {
newImage = [[NSImage alloc] initWithSize:[bitmapImageRep
size]];
[newImage addRepresentation:bitmapImageRep];
[bitmapImageRep release];
if (newImage) {
return [newImage autorelease];
}
}
CFRelease(ref);
}
return nil;
}
FROM : Anthony Mittaz
DATE : Thu Jan 10 05:03:50 2008
Thanks this works well except that when I'm using this code the
resulting image has no shadow under each browser item.
Is there anything i can add to this code the get back my shadows ;-)
Here You can see the original IKImageBrowser and the resulting image.
http://web.mac.com/sync/Site/IKImageBrowserViewProblem.html
**********************************************
** Alexander Griekspoor PhD **
**********************************************
mekentosj.com
4Peaks - For Peaks, Four Peaks
2004 Winner of the Apple Design Awards
Best Mac OS X Student Product
http://www.mekentosj.com/4peaks
**********************************************
_______________________________________________
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