Screen snapshot example code posted
Screen snapshot example code posted
- Subject: Screen snapshot example code posted
- From: Ben Haller <email@hidden>
- Date: Fri, 12 Aug 2005 21:48:12 -0700
Those who have used NSBitmapImageRep's method -
initWithFocusedViewRect: in a transparent window to get a screenshot
probably know that that broke on 10.4 due to changes in the
underlying video architecture. Apple has (through informal channels)
told me that that is unlikely to be fixed, as it was never
particularly documented or intentional behavior to begin with. So a
need for a different method has come about. Thus the example code
I've just posted on my website:
http://www.sticksoftware.com/developer/samplecode.html
This code uses CopyBits to make a QuickDraw Picture, and then gets
it into Cocoa via NSPICTImageRep. It feels a little like pounding a
square peg into a round hole, but it works and it's pretty fast.
Ryan Bates wrote much of this code; I just made it work on
multiple monitors, which turned out to be trivial. As a comment in
the code indicates, it will probably stop working at some point in
the future since CopyBits has been deprecated in 10.4 (talk about the
end of an era), but it works for now. :-> If anybody has better
code they would like to share, that would be most welcome. I
searched the cocoa-dev archives and didn't find anything helpful.
Presumably there's a way to do this through CoreGraphics or
CoreImage, but I don't know those APIs...
I've logged a bug on Apple that they ought to provide an example
of how to do this correctly, using public, non-deprecated APIs. Or
better yet, add a new factory method to NSImage that makes an image
from the screen pixels. I have no idea if they intend to pay any
attention to me. :->
Ben Haller
Stick Software
_______________________________________________
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