zoukankan      html  css  js  c++  java
  • 我写的图片、文件操作类(自己写的,以后用到的时候可以直接用,哈哈哈)

    public partial class ImageHelper
    {
        public static string GetConfiguration(string key)
        {
            return ConfigurationManager.AppSettings[key];
        }
        public static string ImageServer
        {
            get { return GetConfiguration("ImageServer"); }
        }
        public static string GetUrl(string plucode)
        {
            try
            {
                string href;
                if (plucode.Length < 7)
                {
                       href = String.Format("{0}/{1}/{2}/{3}.jpg", ImageServer, "0000000",
                       "00", plucode);
                }
    else if (plucode.Length < 9)
    {
    href = String.Format("{0}/{1}/{2}/{3}.jpg", ImageServer, plucode.Substring(0, 7),
    "00", plucode);
    }
    else
    {
    href = String.Format("{0}/{1}/{2}/{3}.jpg", ImageServer, plucode.Substring(0, 7),
    plucode.Substring(7, 2), plucode);
    }

    return href;
    }
    catch (Exception exception)
    {
    return string.Empty;
    }
    }

    public static string UpLoad(string plucode)
    {
         var openFile = new OpenFileDialog();
         var imageUrl = "";
         if (openFile.ShowDialog() == DialogResult.OK)
         {
             var picpath = openFile.FileName;
             var picname = openFile.SafeFileName;
             var picStream = new FileStream(picpath, FileMode.Open);
             var bytes = GetBytes(picStream);

             var webUpFile = new UpFileContent.webUpFileServiceSoapClient();
             imageUrl = webUpFile.UploadFileByImg(bytes, picname, plucode);
         }
         return imageUrl;
    }

    public static byte[] GetBytes(Stream stream)
    {
         var bytes = new byte[stream.Length];
         stream.Read(bytes, 0, bytes.Length);
         stream.Seek(0, SeekOrigin.Begin);
         return bytes;
    }

    public static Image GetImage(string url)
    {
        try
        {
             var webRequest = WebRequest.Create(url);
             var webResponse = webRequest.GetResponse();

             var stream = webResponse.GetResponseStream();
             var image = Image.FromStream(stream);
             return image;
         }catch(Exception exception)
         {
             return null;
         }
      }
    }

  • 相关阅读:
    JUC------03
    const、define 和 static 的区别
    Mac Catalina 下 gdb codesign问题解决
    k8s 辨析 port、NodePort、targetPort、containerPort 区别
    centos7.8 安装部署 k8s 集群
    【小白学PyTorch】21 Keras的API详解(下)池化、Normalization层
    【小白学PyTorch】21 Keras的API详解(上)卷积、激活、初始化、正则
    【小白学PyTorch】20 TF2的eager模式与求导
    【小白学PyTorch】19 TF2模型的存储与载入
    【小白学PyTorch】18 TF2构建自定义模型
  • 原文地址:https://www.cnblogs.com/fjzhang/p/2963415.html
Copyright © 2011-2022 走看看