将base 64字符串转换为图像并保存
这是我的代码:
protected void SaveMyImage_Click(object sender, EventArgs e) { string imageUrl = Hidden1.Value; string saveLocation = Server.MapPath("~/PictureUploads/whatever2.png") ; HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(imageUrl); WebResponse imageResponse = imageRequest.GetResponse(); Stream responseStream = imageResponse.GetResponseStream(); using (BinaryReader br = new BinaryReader(responseStream)) { imageBytes = br.ReadBytes(500000); br.Close(); } responseStream.Close(); imageResponse.Close(); FileStream fs = new FileStream(saveLocation, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); try { bw.Write(imageBytes); } finally { fs.Close(); bw.Close(); } }}
顶部imageUrl声明采用Base64图像字符串,我想将其转换为图像。我认为我的代码集仅适用于像“www.mysite.com/test.jpg”这样的图像而不适用于Base64字符串。有人有什么建议吗?谢谢!
萧十郎