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;
         }
      }
    }

  • 相关阅读:
    奶酪工厂
    P1080 国王游戏(非高精版)
    【洛谷P2150】[NOI2015] 寿司晚宴
    【洛谷P3349】[ZJOI2016]小星星
    【洛谷P5785】[SDOI2012]任务安排
    【模板】严格次短路
    【洛谷P3647】[APIO2014]连珠线
    2021.10.27NOIP模拟总结
    【树形DP】CF1016F Road Projects
    2021CSP-S 总结
  • 原文地址:https://www.cnblogs.com/fjzhang/p/2963415.html
Copyright © 2011-2022 走看看