Os X And Ctypes: How To Retrieve Raw Pixels From Cgdataprovidercopydata()?
I am trying to capture the screen using only the ctypes modules. Unfortunately I cannot retrieve raw pixel from CGDataProviderCopyData. I need to get an access to raw data: #!/usr/
Solution 1:
I have no experience with the CoreGraphics API, but looking at the documentation it looks like CGDataProviderCopyData
returns a CFDataRef
object. The documentat for CFDataRef
has a section on "Examining a CFData Object" which describes a CFDataGetLength
function and a CFDataGetBytePtr
function which return the length of the data and a UInt8*
.
https://developer.apple.com/library/ios/documentation/CoreFoundation/Reference/CFDataRef/index.html
Solution 2:
Thanks to Snorfalorpagus, I finally succeed:
#...
data = cgs.CGDataProviderCopyData(prov)
data_ref = cgs.CFDataGetBytePtr(data)
buf_len = cgs.CFDataGetLength()
image_data = cast(data_ref, POINTER(c_ubyte * buf_len))
cgs.CGDataProviderRelease(prov)
# Raw pixels are in image_data.contents
Post a Comment for "Os X And Ctypes: How To Retrieve Raw Pixels From Cgdataprovidercopydata()?"