Forum Archive

creating CG types in beta?

JonB

In trying to grab screenshots from a video, I believe I need to define CGImage, and CGImageRef.
Howevever, ObjCClass('CGImage') doesnt find that class.

Looking at the headers, CGImage is just a struct, so I think i can create that type as a structure, however I still need to pass a function pointer to CGImageDestroy, which also doesnt seem to be recognized by the cdll.

I am sure I am missing something incredibly basic....

omz

Just treat CGImageRef as a pointer (c_void_p), and don't worry about the internal structure. It's an "opaque" type, and you'd never access its structure directly in C code either. The CoreGraphics framework (where CGImageRef is defined) is just plain C, not Objective-C, so you usually manipulate its "objects" using functions, e.g. CGImageGetWidth() etc.

It's usually easier to deal with CGImageRef if you wrap it in a UIImage, using +imageWithCGImage: (or some variation, like +imageWithCGImage:scale:orientation:).

JonB

Thanks, i ended up figuring that part out, but wasnt sure because i kept getting crashes. turns out NSError was throwing me off, because i had to pass a pointer to an NSError object, rather than the object itself... or, better yet, None.