我获得了一个返回图像的ashx“服务”。我是ashx文件的新手 - 所以不知道如何处理它。
我需要将图像流式传输到byte []中,以便我可以将其复制到其他地方。我该怎么做?
答案 0 :(得分:3)
您可以使用WebClient.DownloadData指向asxh。
所以,让我给你一个样本。假设您的图像位于asp.net页面上,如下所示:
<img src="http://someServer/someSite/MyHandler.ashx?id=myId"/>
在这种情况下,您可以使用以下代码:
using (System.Net.WebClient wclient = new System.Net.WebClient())
{
byte[] data = wclient.DownloadData(
"http://someServer/someSite/MyHandler.ashx?id=myId");
}
或者您可以使用WebRequest