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);
        }
复制代码

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/12514961.html