C# Image Download

 
  
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Drawing;
5 using System.Drawing.Imaging;
6 using System.IO;
7 using System.Net;
8
9
10 namespace COMP
11 {
12 public class DownloadImage
13 {
14 private string imageUrl;
15 private Bitmap bitmap;
16 /// <summary>
17 /// 涂聚文 2011-05-05
18 ///
19 /// </summary>
20 /// <param name="imageUrl"></param>
21 public DownloadImage( string imageUrl)
22 {
23 this .imageUrl = imageUrl;
24 }
25 /// <summary>
26 ///
27 /// </summary>
28 public void Download()
29 {
30 try
31 {
32 WebClient client = new WebClient();
33 Stream stream = client.OpenRead(imageUrl);
34 bitmap = new Bitmap(stream);
35 stream.Flush();
36 stream.Close();
37 }
38 catch (Exception e)
39 {
40 Console.WriteLine(e.Message);
41 }
42 }
43 /// <summary>
44 ///
45 /// </summary>
46 /// <returns></returns>
47 public Bitmap GetImage()
48 {
49 return bitmap;
50 }
51 /// <summary>
52 ///
53 /// </summary>
54 /// <param name="filename"></param>
55 /// <param name="format"></param>
56 public void SaveImage( string filename, ImageFormat format)
57 {
58 if (bitmap != null )
59 {
60 bitmap.Save(filename, format);
61 }
62 }
63
64 }
65 }

转载于:https://www.cnblogs.com/geovindu/archive/2011/05/06/2038732.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值