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

  • 相关阅读:
    iOS中文API之UITouch详解
    iOS中文API之UIResponder介绍
    NSProxy
    NSObject
    Objective-C 简介
    【摘录】在Windows平台上使用Objective-C
    基于VM10+Win7安装Mac OSX10.11 El Capitan
    关于安装黑苹果
    insta经典滤镜下载
    GPUImage简单滤镜使用之色阶(三)
  • 原文地址:https://www.cnblogs.com/fjzhang/p/2963415.html
Copyright © 2011-2022 走看看