Reputation: 41
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 a instantiated Bitmap into the project folder. I got a Generic Error when I ran the code. The whole bunch of error messages is as below.
System.Exception: Generic Error [GDI+ status: GenericError] at System.Drawing.GDIPlus.CheckStatus (System.Drawing.Status status) [0x00079] in :0 at System.Drawing.Image.Save (System.String filename, System.Drawing.Imaging.ImageCodecInfo encoder, System.Drawing.Imaging.EncoderParameters encoderParams) [0x0003d] in :0 at System.Drawing.Image.Save (System.String filename, System.Drawing.Imaging.ImageFormat format) [0x00044] in :0 at System.Drawing.Image.Save (System.String filename) [0x00008] in :0 at (wrapper remoting-invoke-with-check) System.Drawing.Image:Save (string) at .$FSI_0037.main@ () [0x00006] in <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] in :0
I debugged the code and figured out the following things.
I just started to learn F# and cannot figure out the problem. Could anyone help with this?
Upvotes: 3
Views: 214
Reputation: 41
The problem came from the value of the "SOURCE_DIRECTORY" of the code. In most cases, the value of SOURCE_DIRECTORY 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")
I my case, the value of SOURCE_DIRECTORY is a single "/". Although I still haven't figured out why, the problem described can be solved by specifying an existing directory with the filename in the bitmap save function.
Upvotes: 1