As Size
, Width
and Height
are Get()
properties of System.Drawing.Image
;
How can I resize an Image object
You could try net-vips, the C# binding for libvips. It's a lazy, streaming, demand-driven image processing library, so it can do operations like this without needing to load the whole image.
For example, it comes with a handy image thumbnailer:
Image image = Image.Thumbnail("image.jpg", 300, 300);
image.WriteToFile("my-thumbnail.jpg");
It also supports smart crop, a way of intelligently determining the most important part of the image and keeping it in focus while cropping the image. For example:
Image image = Image.Thumbnail("owl.jpg", 128, crop: "attention");
image.WriteToFile("tn_owl.jpg");
Where owl.jpg
is an off-centre composition:
Gives this result:
First it shrinks the image to get the vertical axis to 128 pixels, then crops down to 128 pixels across using the attention
strategy. This one searches the image for features which might catch a human eye, see Smartcrop() for details.