zoukankan      html  css  js  c++  java
  • 文件流上传图片

    public string SeveImage(string hpf, out string imgaddr)
    {


    bool isSavedSuccessfully = true;
    string fileName = string.Empty;
    string fileNames = string.Empty;
    try
    {
    byte[] arr = Convert.FromBase64String(hpf);

    MemoryStream ms = new MemoryStream(arr);
    Bitmap bmp = new Bitmap(ms);
    string dirpath = string.Empty;

    dirpath = HttpContext.Current.Server.MapPath("/") + @"/uploadimages/Appeal/";
    //var fileName = ImgSavePath + Path.GetRandomFileName() + Path.GetExtension(file.FileName);


    if (!Directory.Exists(dirpath))
    {
    Directory.CreateDirectory(dirpath);
    }
    //string path = Guid.NewGuid().ToString() + ".Gif";//文件名
    string path = Path.GetRandomFileName() + ".png";//文件名
    fileName = path;

    fileNames = dirpath + fileName; //路径
    bmp.Save(fileNames, System.Drawing.Imaging.ImageFormat.Png);
    }
    catch (Exception ex)
    {
    log4net.LogManager.GetLogger("AccessTxt").Info("______意见建议保存图片SeveImage方法" + ex.ToString());
    isSavedSuccessfully = false;
    }

    if (isSavedSuccessfully)
    {
    imgaddr = @"/uploadimages/Appeal/" + fileName; ;
    //return GetWebConfig.GetWebKeyValue("upImageIp") + @"/uploadimages/"+ fileName;
    return @"/uploadimages/" + fileName;
    }
    else
    {
    imgaddr = "";
    return "";
    }
    }

  • 相关阅读:
    [opencv] 生成标定棋盘格
    [opencv] cmake编译opencv并去窗口边框
    [opencv] matlab生成opencv可读的xml
    [matlab] vc++和matlab混合编程
    全息摄影
    [opencv&opengl]多窗口显示
    CPLEX
    ios读取设备姿态并传输
    python: 基本知识记录
    css: position的使用;
  • 原文地址:https://www.cnblogs.com/mingdep/p/5190210.html
Copyright © 2011-2022 走看看