欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# WebClient download image within url and display the downloaded picture automatically in windows os

程序员文章站 2022-05-03 22:49:02
static void WebClientDownLoad() { string url = "http://p4.ssl.cdn.btime.com/t0167dce5a13c3da30d.jpg?size=5012x3094"; WebClient client = new WebClient( ......
static void webclientdownload()
        {
            string url = "http://p4.ssl.cdn.btime.com/t0167dce5a13c3da30d.jpg?size=5012x3094";
            webclient client = new webclient();
            client.downloaddatacompleted += clientdownloaddatacompleted; 
            client.downloaddataasync(new uri(url));

        }

        private static void clientdownloaddatacompleted(object sender, downloaddatacompletedeventargs e)
        {
            byte[] imgbytes = e.result;
            using(memorystream ms=new memorystream(imgbytes))
            {
                image img = image.fromstream(ms);
                img.save("lyf.jpg",imageformat.jpeg);                 
            }
            processstartinfo info = new processstartinfo();
            info.filename = "lyf.jpg";
            info.useshellexecute = true;
            info.verb = string.empty;
            process.start(info);
        }