zoukankan      html  css  js  c++  java
  • 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 }
    哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)
  • 相关阅读:
    android项目手势识别GestureDetector
    android项目获取sim卡序列号
    android项目MD5加密
    android项目自定义组合控件添加属性
    android项目自定义组合控件
    C# 斐波那契数列 递归算法_2018Oct
    Unity3D编程学习 小知识_人物移动导航_2018Oct
    As Beginning
    MFC中View显示框架
    混合积判断线段相交
  • 原文地址:https://www.cnblogs.com/geovindu/p/2038732.html
Copyright © 2011-2022 走看看