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 }
复制代码
posted @   ®Geovin Du Dream Park™  阅读(440)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
< 2011年5月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4
5 6 7 8 9 10 11
点击右上角即可分享
微信分享提示