Reading streams from image on a web page in asp.net

孤街浪徒 提交于 2019-12-12 03:00:58

问题


I have an image bound in the image control in my asp.net website.

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;

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.

How Can I do that?

Thanks in advance.


回答1:


Try this:

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);


来源:https://stackoverflow.com/questions/25133664/reading-streams-from-image-on-a-web-page-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!