获取url地址对应的图像



    /// 
    /// 获取url地址对应的图像
    /// 
    /// 
    /// 
    private Bitmap GetWebPic(string url)
    {
        try 
        { 
            WebResponse response = WebRequest.Create(url).GetResponse();
            Bitmap pic = (Bitmap)Bitmap.FromStream(response.GetResponseStream());
            return pic;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    /// 
    /// 获取url地址对应的图像
    /// 
    /// 
    /// 
    private Bitmap GetWebPic2(string url)
    {
        try
        {
            WebClient client = new WebClient();
            byte[] data = client.DownloadData(url);                       // 获取首个页面内容(无法获取附件)

            System.IO.MemoryStream stream = new System.IO.MemoryStream(); // 创建支持存储区的内存流
            stream.Write(data, 0, data.Length);

            Bitmap pic = (Bitmap)Bitmap.FromStream(stream);
            return pic;

        }
        catch (Exception ex)
        {
            return null;
        }
    }

你可能感兴趣的:(获取url地址对应的图像,C#)