解码base64流到图像 [英] Decoding base64 Stream to image
问题描述
我使用javascript从客户端发送base64编码图像(我正在使用 http为asp.net应用程序创建截屏上传器applet ://supa.sourceforge.net/ )这会向服务器发送一个ajax请求来存储图像。在服务器上我在asp.net应用程序中使用GenericHanlder中的HttpContext。
I am sending base64 encoded image from client side using javascript (I am creating Screenshot uploader applet for asp.net application using http://supa.sourceforge.net/) and this sends an ajax request to server to store the image. At server I am using HttpContext in GenericHanlder in asp.net application.
如何将图像数据从HttpContext转换为服务器上的图像?
How to convert image data from HttpContext to image at server?
推荐答案
<首先,你需要将base 64转换回字节:
First, you need to convert the base 64 back into bytes:
byte[] data = System.Convert.FromBase64String(fromBase64);
然后,您可以将其加载到Image的实例中:
Then, you can load it into an instance of Image:
MemoryStream ms = new MemoryStream(data);
Image img = Image.FromStream(ms);
如果要将其保存到文件中,请使用System.IO.File.WriteAllBytes
If you want to save it to a file instead, use System.IO.File.WriteAllBytes
这篇关于解码base64流到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!