C#如何通过URL下载图片?

生成图片的URL假设是这样:http://localhost/administrator/qrcode.aspx?pid=78

qrcode.aspx.cs的生成图片的部分代码:

Image image = new Bitmap(200, 200);
Graphics g = Graphics.FromImage(image);
try
{
  string url="http://localhost";

  DotNetBarcode bc = new DotNetBarcode();
  bc.Type = DotNetBarcode.Types.QRCode;
  bc.PrintCheckDigitChar = true;
  bc.WriteBar(url, 0, 0, 210, 210, g);

  System.IO.MemoryStream ms = new System.IO.MemoryStream();
  image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

  Response.ClearContent();
  Response.ContentType = "image/Png";

  Response.BinaryWrite(ms.ToArray());
  ms.Dispose();
}
finally
{
  g.Dispose();
  image.Dispose();
}

现在如果我要输入http://localhost/administrator/qrcode.aspx?pid=78&download=true就下载图片到本地要怎么做?


找过一些资料,WebClient.DownloadFile方法不知道怎么用。满足参数download=true的时候使用Image.Save(string filename, ImageFormat format);似乎不起作用,不知道什么原因。

查看回复