zoukankan      html  css  js  c++  java
  • netcore在CentOS7 下使用处理图片的问题

    请看代码,当你在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
  • 相关阅读:
    JMS ActiveMQ研究文档
    HDD-FAT32 ZIP-FAT32
    C++中出现的计算机术语2
    提供一个免费的CSDN下载账号
    读完了csapp(中文名:深入理解计算机系统)
    IOS成长之路-Nsstring中搜索方法rangeOfString
    PHP汉字转拼音的两种方法+PHP提取汉字(中文)方法
    最小二乘法
    防止tab页重复的去请求服务端
    探索Android中的Parcel机制(上)
  • 原文地址:https://www.cnblogs.com/wujh/p/12063976.html
Copyright © 2011-2022 走看看