Learn how to resize images programmatically in C#: https://blog.aspose.com/2021/12/20/resize-images-in-csharp/
Last active
December 20, 2021 17:47
-
-
Save aspose-com-gists/5690a325b2be179883a03f7179c471f0 to your computer and use it in GitHub Desktop.
Resize Images using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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