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

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

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

 

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

上一篇:虚拟机设置NAT


下一篇:C#图解教程(第四版)—03—类和继承