MonoTouch: UIImage.asJPEG needs an NSError object

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

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

The problem is that you can no longer just create an empty NSError to pass this way ( Obsolete )

 NSError err = new NSError(); //Obsolete 

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

+4
source share
2 answers

In .NET, you should not initialize any out parameter (as opposed to ref parameters), since this is the job of the called method for this.

eg.

 NSError err; // unitialized UIImage img = ...; img.AsPNG ().Save (url, true, our err); if (err != null && err.Code != 0) { // error handling } 
+8
source

Only the empty default constructor for NSError is deprecated, not the NSError class itself. Feel free to specify the appropriate domain and code for your script and pass it on. It should work fine.

+1
source

Source: https://habr.com/ru/post/1383728/


All Articles