Отображение URL-адреса изображения в C# PictureBox: несколько методов

Чтобы отобразить URL-адрес изображения в C# PictureBox, вы можете использовать следующие методы:

Метод 1: использование класса WebClient

using System;
using System.Net;
using System.Windows.Forms;
// ...
string imageUrl = "https://example.com/image.jpg";
using (WebClient webClient = new WebClient())
{
    byte[] imageData = webClient.DownloadData(imageUrl);
    using (var stream = new System.IO.MemoryStream(imageData))
    {
        PictureBox pictureBox = new PictureBox();
        pictureBox.Image = Image.FromStream(stream);
        // Add the PictureBox control to your form
    }
}

Метод 2: использование метода Image.FromFile

using System;
using System.Drawing;
using System.Windows.Forms;
// ...
string imageUrl = "C:\\path\\to\\image.jpg";
PictureBox pictureBox = new PictureBox();
pictureBox.Image = Image.FromFile(imageUrl);
// Add the PictureBox control to your form

Метод 3: использование метода Image.FromStream

using System;
using System.IO;
using System.Net;
using System.Windows.Forms;
// ...
string imageUrl = "https://example.com/image.jpg";
WebRequest request = WebRequest.Create(imageUrl);
using (WebResponse response = request.GetResponse())
using (Stream stream = response.GetResponseStream())
{
    PictureBox pictureBox = new PictureBox();
    pictureBox.Image = Image.FromStream(stream);
    // Add the PictureBox control to your form
}