I have very large images (jpg) and i want to write a csharp program to loop through the files and reduce the size of each image by 75%.
I tried this:
Image thumbNail = image.GetThumbnailImage(800, 600, null, new IntPtr());
but the file size is still very large.
Is there anyway to create thumbnails and have the filesize be much smaller?
Compress your image. For thumbnails, JPEG is sufficient, as you're not looking for quality.
From
GetThumbnailImage
's documentation:I'd suggest you use smaller width and height values. Try:
See sample code.
Also read the documentation:
I think you may want to take a look at the scaling API.
This method helped me very well. Low image size, maintains aspect ratio
These are needed
ImageMagick is a command line tool which is hugely powerful for doing image manipulation. I've used it for resizing large images and thumbnail creation in circumstances where the aspect ratio of the source image is unknown or is unreliable. ImageMagick is able to resize images to a specific height or width while maintaining the original aspect ratio of your picture. It can also add space around an image if required. All in all very powerful and a nice abstraction from having to deal with .nets Image APIs. To use the imageMagick command line tool from within C# I recommend using the System.Diagnostics.ProcessStartInfo object like so:
Using the scale% paramater you can easily reduce the size of your image by 75%
Usage:
That will compress Test.jpg with a quality of 10 and save it as Test2.jpg.
EDIT: Might be better as an extension method:
Usage: