Base64解密轉圖片

string imgname = DateTime.Now.ToString("yyyyMMddhhmmss") + ".gif";

 

string zipPath = AppDomain.CurrentDomain.BaseDirectory;

string filesPath = zipPath + (zipPath.EndsWith("\\") ? "" : "\\") + "GzImage\\";

if (!Directory.Exists(filesPath))

{

    Directory.CreateDirectory(filesPath);

}

string filename = filesPath + imgname;

byte[] arr = Convert.FromBase64String(Img64Str);//base64轉byte

string newImg64Str = Encoding.Default.GetString(arr);//解密

byte[] arr2 = Convert.FromBase64String(newImg64Str);//base64轉byte

 

using (MemoryStream ms2 = new MemoryStream(arr2))

{

    System.Drawing.Bitmap bmp2 = new System.Drawing.Bitmap(ms2);

    bmp2.Save(filename, System.Drawing.Imaging.ImageFormat.Gif);

    bmp2.Dispose();  

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章