On Sep 10, 2009, at 7:32 AM, Jason Foreman wrote:

I am attempting to use the CGWindowListCreateImage function to capture a desktop screenshot. The following code (taken straight from the SonOfGrab sample) works on Leopard, but is failing on Snow Leopard:

CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);

On Leopard, the returned CGImageRef is what I expect: an image of the desktop and all on-screen windows.

On Snow Leopard, the CGImageRef is NULL and the following message is printed to the console:

        <Error>: CGImageCreate: invalid image bits/pixel or bytes/row.

I have filed a bug (7212104), but wonder if there is a workaround that I can use in the meantime, or if I should just use another method of capturing the desktop. Has anyone else encountered this issue?


Your bug will end up dup'd to <rdar://problem/7022171>. The basic problem is using CGRectInfinite from a 32-bit process when the Window Server is running as a 64-bit process – when the rect comes out at the other end it is no longer interpreted as "infinite" but rather as "very very large". Since you can't create an image that large, the creation code fails and you get back a NULL CGImageRef instead.

The current best work around is to determine a proper bounding box for the desktop and pass it for the given rect.
--
David Duncan
Apple DTS Animation and Printing

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to