Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonoTouch: UIImage.asJPEG needs a NSError object

To save a UIImage to a PNG or JPEG locally you call the asPNG().Save(...) function.

The asPNG().Save() function requires an out NSError

The problem is that you can no longer just create a blank NSError to pass in like this (Obsolete)

NSError err = new NSError();  //Obsolete

So, to use the Save() function in MonoTouch, how do we create an NSError() object now?

like image 353
Ian Vink Avatar asked Jan 18 '23 04:01

Ian Vink


1 Answers

In .NET you do not have to initialize any out parameter (in contrast to ref parameters) since it's the called method job to do so.

E.g.

NSError err; // unitialized
UIImage img = ...;
img.AsPNG ().Save (url, true, our err);
if (err != null && err.Code != 0) {
    // error handling
}
like image 54
poupou Avatar answered Jan 30 '23 18:01

poupou