Common error when saving bitmap in Xamarin
open System.Drawing
let bitmap = new Bitmap(16,16)
let path = __SOURCE_DIRECTORY__
bitmap.Save(path+"bitmap.png")
I wrote the code above to save the generated Bitmap to the project folder. When I ran the code, I got a general error. All error information is listed below.
System.Exception Error: Generic error [GDI + status: GenericError] at System.Drawing.GDIPlus.CheckStatus (System.Drawing.Status state) [0x00079] at: 0 at System.Drawing.Image.Save (Filename System.String , System.Drawing.Imaging.ImageCodecInfo encoder, System.Drawing.Imaging.EncoderParameters encoderParams) [0x0003d] to: 0 in System.Drawing.Image.Save (file name System.String, format System.Drawing.Imaging.ImageFormat) [ 0x00044] to: 0 to System.Drawing.Image.Save (filename System.String) [0x00008] to: 0 at (wrapper remoting-invoke-with-check) System.Drawing.Image: Save (string). $ FSI_0037.main @ () [0x00006] at <4081182357644f828a64898ac573806b>: 0 at (wrapper managed-to-native) System.Reflection.MonoMethod: InternalInvoke (System.Reflection.MonoMethod, object, object [], System.Exception &) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object [] parameters, System.Globalization.CultureInfo culture) [0x00032] to: 0
I debugged the code and figured out the following.
- the line of code to create the bitmap worked fine
- The path in this situation was "/"
- the code was fine before the Save () function was called
I've just started learning F # and can't figure out the problem. Can anyone help with this?
source to share
The problem arose from the " SOURCE_DIRECTORY " value of the code. In most cases, the SOURCE_DIRECTORY value does not contain a "/" at the end of it. So the last line of code can be changed to the code below.
bitmap.Save(path+"/bitmap.png")
In my case, the SOURCE_DIRECTORY value is a single "/". Although I still don't understand why the described problem can be solved by specifying the existing directory with the file name in the save bitmap function.
source to share