zoukankan      html  css  js  c++  java
  • winfrom 显示网站图片

        


         private void ThreadShowImage(MyImage obj)
            {
                Thread t = new Thread(new ParameterizedThreadStart(ShowImage));
                t.IsBackground = true;
                try
                {
                    t.Start(obj);
                }
                catch
                {
                    return;
                }
            }
    ==============================================================  
    封装 图片对象类
    public class MyImage
        {
            private PictureBox _pic;  图片空间
           private string _url;         地址
           private Bitmap _image;  图片
           public MyImage(PictureBox p_pic,string p_url)
            {
                _pic = p_pic;
                _url = p_url;
            }
            public string Url
            {
                get { return _url; }
                set { _url = value; }
            }
            public PictureBox Pic
            {
                get { return _pic; }
            }
            public Bitmap Image
            {
                get { return _image; }
                set { _image = value; }
            } 
        }






          private void ShowImage(object obj)
            {
                MyImage image = obj as MyImage;

                image.Pic.BackgroundImage = global::WinForm.Properties.Resources.loading; // 默认等待图片
             try
                {
                    System.Net.WebClient w = new System.Net.WebClient();
                    byte[] bytes = w.DownloadData(image.Url);
                    MemoryStream ms = new MemoryStream(bytes);
                    Image img = Image.FromStream(ms);
                    image.Pic.BackgroundImage = img;
                }
                catch
                {
                    image.Pic.BackgroundImage = global::WinForm.Properties.Resources.smile_sad_48; 
                    return;
                }
             

            }

    在方法中调:

         MyImage    image= new MyImage(pic, "http://.....");     pic为图片控件
        ThreadShowImage( image) ;


  • 相关阅读:
    continue语句及小案例
    break语句和break版猜数字游戏
    python 用while语句打印99乘法表
    python2中引入python3中print函数的语法的语句
    【猜数字 小游戏】
    【while循环】
    代码块和缩进
    使用vs2015编写c语言的方法
    This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details
    矩阵相乘法则和技巧
  • 原文地址:https://www.cnblogs.com/xianzuoqiaoqi/p/1559739.html
Copyright © 2011-2022 走看看