如何把一个Post过来的图片Base64编码转化为Stream
private void Page_Load(object sender, System.EventArgs e)
{
string url = Request.QueryString["Photo"];
byte[] byt = Convert.FromBase64String(url);
Response.Clear();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(byt);
Response.End();
}
{
string url = Request.QueryString["Photo"];
byte[] byt = Convert.FromBase64String(url);
Response.Clear();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(byt);
Response.End();
}
从Request中可以获得Base64编码格式的字符串,然后可以通过Convert.FromBase64String方法把图片转化
为2进制数组,然后通过Response打到页面上显示出来
但如何把图片转化为字符流呢
进行Base64编码的
byte[] byt = Convert.FromBase64String(url);
Stream stream = new MemoryStream(html2bytes);
如果是没有进行Base64编码的,假如说是一段纯文本
Stream stream = null;
string html= "dsf3D43dsds3g8dfdsfdsfsadfdsfjhgkhgkj678gdrkl65kjf94jdf8f8这个不是是Base64编码";
byte[] html2bytes = System.Text.Encoding.ASCII.GetBytes(html);
stream = new MemoryStream(html2bytes);