C# bsae64转图片并保存到服务器

            string base64data = base64.Split(',')[0];
            base64 = base64.Replace(base64data + ",", "");
            byte[] arr = null;
            try {
                arr = Convert.FromBase64String(base64);
            }
            catch {
                return "";
            }
          
            string zt = "err";
            using (MemoryStream ms = new MemoryStream(arr))
            {
                using (Bitmap bmp = new Bitmap(ms))
                {
                    try
                    {
                        string path = HttpContext.Current.Server.MapPath("/Images/");
                        if (!Directory.Exists(path))//如果日志目录不存在就创建
                        {
                            Directory.CreateDirectory(path);
                        }
                        string Pic_Path = path + "/" + openid + ".jpg";
                        bmp.Save(Pic_Path, System.Drawing.Imaging.ImageFormat.Jpeg);
                        bmp.Dispose();//释放资源,用完千万别忘记释放                        
                        if (typ == "1")
                        {
                            zt = DisIdcard(base64);
                        }
                        else
                        {
                            zt = "{}";
                        }
                    }
                    catch
                    {

                    }
                }
            }
c#
63 views
Comments
登录后评论
Sign In