Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Created April 23, 2025 18:46
Show Gist options
  • Save conholdate-gists/72882d13dd231d82157e86ff0451517e to your computer and use it in GitHub Desktop.
Save conholdate-gists/72882d13dd231d82157e86ff0451517e to your computer and use it in GitHub Desktop.
Resize Image in C# | Scale JPG PNG GIF BMP Picture
// Load image
using (Image image = Image.Load("aspose-logo.png"))
{
// Cache image data
if (!image.IsCached)
{
image.CacheData();
}
// Specify width and height
int newWidth = image.Width / 2;
image.ResizeWidthProportionally(newWidth);
int newHeight = image.Height / 2;
image.ResizeHeightProportionally(newHeight);
// Save image
image.Save("ResizeImageProportionally_out.png");
// Load image
using (Image image = Image.Load("aspose-logo.jpg"))
{
// Resize image and save the resized image
image.Resize(300, 300);
image.Save("SimpleResizing_out.jpg");
}
// Load image
using (Image image = Image.Load("image.svg"))
{
// Resize image as PNG
image.Resize(image.Width * 10,image.Height * 15);
image.Save("Logotype_10_15.png", new PngOptions()
{
VectorRasterizationOptions = new SvgRasterizationOptions()
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment