Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 20, 2021 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/5690a325b2be179883a03f7179c471f0 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/5690a325b2be179883a03f7179c471f0 to your computer and use it in GitHub Desktop.
Resize Images using C#
// 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, ResizeType.LanczosResample);
image.Save("SimpleResizing_out.jpg");
}
// 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