c#base64 그림을 로컬로 저장

1257 단어 c#base64서버
     public string Base64ToImage(string base64Str,string path, string imgName)
        {
            string filename = "";// string 
            // 
            string hz = base64Str.Split(',')[0].Split(';')[0].Split('/')[1];
            string[] str = base64Str.Split(',');  //base64Str base64 , 
            byte[] imageBytes = Convert.FromBase64String(str[1]);
            // MemoryStream 
            MemoryStream memoryStream = new MemoryStream(imageBytes, 0, imageBytes.Length);
            memoryStream.Write(imageBytes, 0, imageBytes.Length);
            filename = path + imgName + "." + hz;// 
            string tmpRootDir = Server.MapPath(path); //  
            if (!Directory.Exists(tmpRootDir))
            {
                Directory.CreateDirectory(tmpRootDir);
            }
            string imagesurl2 = tmpRootDir + imgName + "." + hz; //  
            //   
            Image image = Image.FromStream(memoryStream);
            //    
            string iname = DateTime.Now.ToString("yyMMddhhmmss");
            image.Save(imagesurl2);  //  Server.MapPath("pic\\") + iname + "." + hz
            return filename;
        }

좋은 웹페이지 즐겨찾기