This example shows how to manually make a number of thumbnail images from an original.
1
Creating the Bitmap

We will need a bitmap of the original image so we create it here.

[C#]

Image image = Bitmap.FromFile(Server.MapPath("rez/sora-sagano-8sOZJ8JF0S8-unsplash.jpg"));
try {


2
Iterating Sizes

We work in a loop, iterating through the different widths that we want. For each width we establish a suitable size by scaling the image size down.

[C#]

  foreach (double width in new double[] { 240, 160, 80 }) {
    Size size = image.Size * (width / image.Width);


3
Making the Thumbnail

We get the thumbnail image and then dispose of the larger image.

[C#]

    Image thumb;
    try {
      thumb = image.GetThumbnailImage(size.Width, size.Height);
    }
    finally {
      image.Dispose();
    }


4
Saving

We save the thumbnail and then it becomes the image input for the next iteration. This way the amount of image scaling is kept to a minimum.

[C#]

    thumb.Save(Server.MapPath($"Making_Thumbnails_Complete_6_{width}.jpg"));
    image = thumb;


5
Tidying Up

At the end we dispose of the last image.

[C#]

  }
}
finally {
  image.Dispose();
}


6
Input and Output

Sample input and output images are shown below.


sora-sagano-8sOZJ8JF0S8-unsplash.jpg


Making_Thumbnails_Complete_6_240.jpg


Making_Thumbnails_Complete_6_160.jpg


Making_Thumbnails_Complete_6_80.jpg