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(涂聚文)
  • 相关阅读:
    layer备忘
    Java中遍历Map对象的4种方法
    为什么Java中1000==1000为false而100==100为true?
    linux系统安装psycopg2
    centos7源码安装mysql5.7
    Azure Sql
    javascript和jQuery动态修改css样式的方法
    Git early EOF index-pack failed 问题
    C# 多线程——SemaphoreSlim的使用
    Docker 可视化
  • 原文地址:https://www.cnblogs.com/geovindu/p/2038732.html
Copyright © 2011-2022 走看看