• 文件流上传图片


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

  • 相关阅读:
    暑假训练第三周总结
    UVA 1212 Duopoly
    UVA 12125 March of the Penguins
    UVA 1345 Jamie's Contact Groups
    UVA 10806 Dijkstra, Dijkstra.
    暑假训练第一周总结
    HDU 5792 World is Exploding
    HDU 5791 Two
    HDU 5787 K-wolf Number
    Sql With as 用法
  • 原文地址:https://www.cnblogs.com/mingdep/p/5190210.html
Copyright © 2020-2023  润新知