網頁圖片下載
想要下載網站上的照片, 並儲存到硬碟裏, 只需使用WebClient.DownloadFile(string url, string fileName)即可
System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
saveFileDialog.Filter = "JPeg Image|*.jpg";
saveFileDialog.FileName = string.Format("{0}", "預設檔名");
string url="/wp-content/uploads/2016/10/img_6279.jpg"
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
new WebClient().DownloadFile(url, saveFileDialog.FileName);
Image Widget儲存
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
BitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create((BitmapImage)img.Source));
using (var fileStream = new System.IO.FileStream(saveFileDialog.FileName, System.IO.FileMode.Create))
{
encoder.Save(fileStream);
}
}