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

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);
        }

 

posted @ 2020-03-17 17:14  FredGrit  阅读(331)  评论(0编辑  收藏  举报