[英]Reading streams from image on a web page in asp.net
I have an image bound in the image control in my asp.net website. 我在asp.net网站的图像控件中绑定了图像。
I am using C# to develop it. 我正在使用C#开发它。 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. 现在,我想在另一个事件中从该图像控件(testImage)中获取流。 I dont want to save the image in any server path.
我不想将图像保存在任何服务器路径中。
How Can I do that? 我怎样才能做到这一点?
Thanks in advance. 提前致谢。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.