I am attempting to save the currently visible ui.View to a JPEG image file however when it saves it always returns a blank white JPEG image. My current code.
def captureNow(sender):
print "Capture Screen"
layer = v.layer()
UIGraphicsBeginImageContext(layer.bounds().size)
layer.renderInContext_(UIGraphicsGetCurrentContext())
# v.drawViewHierarchyInRect_afterScreenUpdates_(v.bounds(), True)
image = ObjCInstance(UIGraphicsGetImageFromCurrentImageContext())
UIGraphicsEndImageContext()
vt = ui.View()
vt.width = 800
vt.height = 600
UIImageView = ObjCClass('UIImageView')
iview = UIImageView.alloc().initWithImage_(image)
iview.setFrame_(ObjCInstance(vt).bounds())
print iview
ObjCInstance(vt).addSubview_(iview)
vt.present('sheet')
UIImageJPEGRepresentation(image, 1.0).writeToFile_atomically_('test.jpg', True)
def UIImageJPEGRepresentation(image, compressionQuality):
func = c.UIImageJPEGRepresentation
func.argtypes = [ctypes.c_void_p, ctypes.c_float]
func.restype = ctypes.c_void_p
return ObjCInstance(func(image.ptr, compressionQuality))
I have attempted to check to see if it is the result of saving it from a UIImage object to NSData and then to a file by trying to show the UIImage in a UIImageView however I cannot get that to work.