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

 

你可能感兴趣的:(C# WebClient download image within url and display the downloaded picture automatically in windows os)