The problem of using netcore to process pictures under CentOS7

Please see the code, when you want to convert the picture to Base64 under centos

 1             MemoryStream ms = new MemoryStream();
 2             try
 3             {
 4                 Bitmap bmp = new Bitmap(filePath);
 5                 bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
 6 
 7                 byte[] arr = new byte[ms.Length];
 8                 ms.Position = 0;
 9                 ms.Read(arr, 0, (int)ms.Length);
10                 return Convert.ToBase64String(arr);
11             }
12             catch (Exception ex)
13             {
14                 Core.Helpers.Log4NetHelper.WriteError(typeof(string),ex);
15                 return "";
16             }
17             finally
18             {
19                 ms.Close();
20             }

Obviously it is normal for you to be on the local or windows server, but the following exception will be thrown under linux:

System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libgdiplus': The specified module could not be found.
   at System.Runtime.InteropServices.FunctionWrapper`1.get_Delegate()
   at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
   at System.Drawing.SafeNativeMethods.Gdip..cctor()
   --- End of inner exception stack trace ---
   at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromFile(String filename, IntPtr& bitmap)
   at System.Drawing.Bitmap..ctor(String filename, Boolean useIcm)

Read the error message and know that Linux does not have libgdiplus

solution:

#locate libdl
#cd /usr/lib64 #ln -s libdl-2.17.so libdl.so

If locate libdl reports the following error:
-bash: locate: command not found

The reason is that the mlocate package is not installed

Install the package: #yum -y install mlocate

Update the library again: #updatedb

Finally, the most important thing is to install the libgdiplus library and get it done!

 

yum install libgdiplus-devel

Guess you like

Origin blog.csdn.net/qq_45533841/article/details/112060800