问题
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