从asp.net中的网页上的图像中读取流 [英] Reading streams from image on a web page in asp.net
本文介绍了从asp.net中的网页上的图像中读取流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在asp.net网站的图像控件中绑定了一个图像。
I have an image bound in the image control in my asp.net website.
我正在使用C#来开发它。在代码下面绑定图像。
I am using C# to develop it. Below the code to bind the image.
byte[] imageBytes = System.IO.File.ReadAllBytes("filepath");
string base64String = Convert.ToBase64String(imageBytes, 0, imageBytes.Length);
this.testImage.Src = "data:image/jpeg;base64," + base64String;
现在我想在另一个事件中从该图像控件(testImage)中获取流。
我不想在任何服务器路径中保存图像。
Now I want to take the streams from that image control (testImage) in another event. I dont want to save the image in any server path.
我该怎么做?
提前致谢。
推荐答案
试试这个:
WebClient webClient = new WebClient();
Image img = Image.FromStream(webClient.OpenRead(path));
webClient.Dispose();
仅当图像不是硬盘上的文件时才适用。
That applies only if the image is not a file on your hard disk.
如果图像在硬盘上,则应该这样做:
And if the image is on the hard disk, this should do it:
Image img = Image.FromFile(path);
这篇关于从asp.net中的网页上的图像中读取流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文