The AsJPEG method calls UIImageJPEGRepresentation , and its return value is documented as:
A data object containing JPEG data, or nil if there is a problem creating the data. This function can return zero if the image has no data or if the underlying CGImageRef contains data in an unsupported bitmap format.
Like many APIs on iOS (and OSX), where the exception is usually not used (and null used to report any error).
In any case, you should check your image sizes and properties - they may give you a hint that it does not translate into a JPEG bitmap.
In addition, since NSData can represent a very large amount of memory, you should try to limit its life, for example:
using (NSData imageData = CroppedImageView.Image.AsJPEG ()) { NSError err; if (!imageData.Save ("tmp.jpg", true, out err)) { Console.WriteLine("Saving of file failed: " + err.Description); } }
source share