base64数据转图片,返回图片地址

/// 
        /// base64 转图片,返回图片地址
        /// 
        /// 
        public static string Base64StringToImage(string strbase64)
        {

            try
            {
                byte[] arr = Convert.FromBase64String(strbase64);
                MemoryStream ms = new MemoryStream(arr);
                System.Drawing.Image img = System.Drawing.Image.FromStream(ms);

                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "images\\");
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);

                DateTime danow = DateTime.Now;

                string FullFilePath = Path.Combine(path, danow.ToString("yyyyMMddHHmmssfff") + ".jpg");

                img.Save(FullFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);

                //System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                //img.Save("ImgName.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                //img.Save("ImgName.bmp", ImageFormat.Bmp);
                //img.Save("ImgName.gif", ImageFormat.Gif);
                //img.Save(@"images\ImgName.png", ImageFormat.Png);

                return FullFilePath;
            }
            catch (Exception ex)
            {
                WriteLog("图片转换报出异常,异常信息:" + ex.Message);
                return "";
            }
        }

 

你可能感兴趣的:(C#)