I have a need to do some drawing using some of the abilities that the objective-c CGContext api has available to it, but I am having trouble figuring out how to be able to make calls to the various CGContext-related functions.
I found this old thread, which does some things with a graphics context:
https://forum.omz-software.com/topic/2327/uiimagejpegrepresentation/1
But it doesn't illustrate very clearly how it manages to successfully call functions like:
UIGraphicsGetCurrentContext()
UIGraphicsGetImageFromCurrentImageContext()
It seems like I can call:
context = objc_util.c.UIGraphicsGetCurrentContext()
but if I try to use that context ref value in any CGContext draw function, like
objc_util.c.CGContextFillRect(uicontext, r)
it crashes hard. I was pretty sure that was invalid...but I'm not clear on how to call plain objective-c functions like this. There's examples of more complex creation/calling of functions in that thread I linked to above:
def CGBitmapContextCreate(baseAddress, width, height, param_0, bytesPerRow, colorSpace, flags):
func = c.CGBitmapContextCreate
func.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int32]
func.restype = ctypes.c_void_p
print ObjCInstance(colorSpace).ptr
result = func(baseAddress, width, height, param_0, bytesPerRow, ObjCInstance(colorSpace).ptr, flags)
print result
if result is not None:
return result
else:
raise RuntimeError('Failed to create context')
But I'm not clear on when/how/why you use that sort of setup.