Windows Forms: How to Create Thumbnail Image in C#

This post shows you How to create thumbnail image in C# Windows Forms Application.

Dragging PictureBox, Button from the Visual Studio toolbox into your form desinger, then design a simple layout allows you to open an image, then get the thumbnail image as shown below.

c# create thumbnail image

C# get thumbnail from file

Adding a click event handler to the Convert button allows you to open an image, then convert to the thumbnail image.

private void btnConvert_Click(object sender, EventArgs e)
{
    using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "JPEG|*.jpg" })
    {
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            Image image = Image.FromFile(ofd.FileName);
            pictureBox1.Image = image;
            pictureBox2.Image = image.GetThumbnailImage(70, 70, () => false, IntPtr.Zero);
        }
    }
}

You can also create a CreateThumbnailImage method allows you to create a thumbnail image from a larger image in c#.

public static Image CreateThumbnailImage(string url, int width = 65, int height = 80)
{
    Image image = Image.FromFile(url);
    Image thumb = image.GetThumbnailImage(width, height, () => false, IntPtr.Zero);
    image.Dispose();
    return thumb;
}

Creating a thumbnail image is often used when uploading an image to a website. The thumbnail image will be displayed in the post's brief description.