要下載并顯示URL中的圖片,可以使用以下步驟:
WebRequest類從URL中下載圖片文件到本地計算機??梢允褂靡韵麓a示例:using System.Net;
string url = "https://example.com/image.jpg";
string localPath = "C:\\path\\to\\save\\image.jpg";
using (WebClient client = new WebClient())
{
client.DownloadFile(url, localPath);
}
Image類加載本地文件中的圖片,并將其設置為PictureBox的顯示圖片??梢允褂靡韵麓a示例:using System.Drawing;
string imagePath = "C:\\path\\to\\save\\image.jpg";
Image image = Image.FromFile(imagePath);
pictureBox1.Image = image;
這樣就可以從URL中下載圖片文件并顯示在PictureBox中。請確保在使用完后及時釋放資源,以避免內存泄漏。