resize images in c#

We often get images with the size that doesn’t meet our requirements, therefore, we have to resize them accordingly. In this article, you will learn how to resize images in C# from within your .NET applications. Moreover, with the help of C# code samples, we will demonstrate how to resize raster and vector images.

Resize Images in C# - API Installation

To resize images. we will use Aspose.Imaging for .NET. It is a powerful image processing API to manipulate various types of raster and vector images. You can download the API’s DLL or install it via NuGet.

PM> Install-Package Aspose.Imaging

Resize Raster Images in C#

There are two methods to resize raster images (PNG, GIF, JPEG, etc.): simple resizing and resizing using a resize type. In simple resizing, the images are resized by providing the height and width. Whereas, the second method uses different resizing techniques. The following sections demonstrate how to resize an image using each of the above-mentioned methods.

Simple Image Resizing in C#

The following are the steps to resize an image in C#.

The following code sample shows how to resize an image in .NET applications.

C# Resize Image with a Resize Type

The ResizeType enum is used to specify resizing techniques that you can use as per your requirements. The complete list of supported resizing types is available here. The following are the steps to resize an image using a particular resize technique.

The following code sample resizes the image using a particular resize technique.

Proportional Image Resizing in C#

Resizing images by specifying height and width may result in a shrunk or scaled image. Therefore, you have to calculate the aspect ratio manually. However, any miscalculation in aspect ratio may lead to a stretched image. To avoid such issues, you can use proportional resizing. The following are the steps to achieve this.

In case you want to use any particular resize type while resizing images proportionally, use the overload methods Image.ResizeWidthProportionally(Int32, ResizeType) and Image.ResizeHeightProportionally(Int32, ResizeType).

The following code sample shows how to resize an image proportionally using C#.

Resize Vector Images in C#

Aspose.Imaging for .NET also allows you to resize the vector images and save them in a raster image format. The following code sample shows how to resize an SVG image and save the output in PNG format.

C# Resize Images with a Free License

You can get a free temporary license to resize images without evaluation limitations.


In this article, you have learned how to resize images programmatically in C#. Furthermore, the code samples have demonstrated how to perform simple resizing of images or resizing using a particular type. We have also covered how to avoid manual calculation of aspect ratio while resizing images. In addition, resizing of vector images is also discussed at the end. Besides, you can explore more about the .NET image processing API using documentation. Also, you can download the complete package of source code samples from GitHub. In case of any queries, you can contact us on our forum.

See Also