If (bitmap!=null)
{
//create the folder
Var folderPath=dir. Substring (0, dir. LastIndexOf ('/'));
CreateDir (folderPath);
//picture suffix format
Var suffix=dir. Substring (dir. LastIndexOf ('. ') + 1, dir. Length - dir. LastIndexOf ('. ') - 1). The ToLower ();
Var suffixName suffix of==="PNG"? ImageFormat. Png:
Suffix=="JPG" | | suffix=="jpeg"? ImageFormat. Jpeg:
The suffix=="BMP?" " ImageFormat. Bmp:
Suffix=="GIF"? ImageFormat. Gif: ImageFormat. Jpeg;
//a copy here to save the image, otherwise there will be a "general error occurred in GDI +" error
Var bmpNew=new Bitmap (Bitmap);
BmpNew. Save (GetPath (dir), suffixName);//it will be a general error occurred in GDI +, o great god
BmpNew. The Dispose ();
Bitmap. The Dispose ();
CodePudding user response:
There are many reasons to GDI + exception, but the exception thrown all the same, which bring many difficulties to troubleshoot errors, this also is the characteristics of managed objects,From your description, there are two things need to pay attention to you because there was a GDI + exception, so to copy an object, it need to be considered, at the start of the exception object is not did not bring the copy, so copy the object may not be able to solve, the second is new really represents an object replication, this also need to see documentation,
If your Bitmap is derived from Base64, generally do not need to copy an object is saved, because there will not be occupied,
I suggest or find out the real reason for GDI + exception,
CodePudding user response:
We want to know is, here and there to base64?And if he is a base64, why are you going to use bitmap receive again,
That is, if there is a doc file, I read file bytes and base64, transfer to third party, so he why base64 decoding to byte, use word to open and then use word save doc??
Isn't that file, but the bitmap data?
CodePudding user response:
Base64 string can be converted into the byte [].Byte [] directly into the picture..
IO. Writeallbytes (" 1. JPG ");
Suffix??? Not important suffix just influencing the way file in Windows open...