当前位置: 移动技术网 > 科技>操作系统>Linux > netcore在CentOS7 下使用处理图片的问题

netcore在CentOS7 下使用处理图片的问题

2019年12月19日  | 移动技术网科技  | 我要评论

请看代码,当你在centos下要把图片转为base64的时候

 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             }

明明你在本地或windows服务器是正常的,可是在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)

看了报错信息知道 linux没有 libgdiplus

解决方案:

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

如果 locate libdl 报以下错误:
-bash: locate: command not found

其原因是没有安装mlocate这个包

安装一下包:#yum  -y install mlocate

再更新一下库:#updatedb

最后最关键的是安装一下 libgdiplus 库,搞定!

 

yum install libgdiplus-devel

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网