Jos*_*osh 139
WebClient.DownloadData是最简单的方法.
var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData("http://www.google.com/images/logos/ps_logo2.png");
Run Code Online (Sandbox Code Playgroud)
第三方编辑:请注意WebClient是一次性的,因此您应该使用using
:
string someUrl = "http://www.google.com/images/logos/ps_logo2.png";
using (var webClient = new WebClient()) {
byte[] imageBytes = webClient.DownloadData(someUrl);
}
Run Code Online (Sandbox Code Playgroud)
Dun*_*unc 14
如果您需要异步版本:
using (var client = new HttpClient())
{
using (var response = await client.GetAsync(url))
{
byte[] imageBytes =
await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
}
}
Run Code Online (Sandbox Code Playgroud)