I have a console application that successfully re-sizes an image while maintaining aspect ratio.
I now need to crop the image the code I am using is below:
using (var thumbnail = CropPicture(image, rectangle)) {
EncoderParameters encParams = new EncoderParameters(1);
encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)90);
thumbnail.Save(destination, GetImageCodecInfo(image.RawFormat), encParams);
}
public static Image CropPicture(Image source, Rectangle cropArea) {
using (var bitmap = new Bitmap(source)) {
return (Image)(bitmap.Clone(cropArea, source.PixelFormat));
}
}
It seems to be throwing an Out of memory exception on the line
return (Image)(bitmap.Clone(cropArea, source.PixelFormat));
Any ideas what's going on? I think it's an open file can't be 100% sure.