C# image manipulation using a console application throwing 'Out of Memory' Exception -


i have console application re-sizes image while maintaining aspect ratio.

i need crop image code using 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 throwing out of memory exception on line

return (image)(bitmap.clone(croparea, source.pixelformat)); 

any ideas what's going on? think it's open file can't 100% sure.

according msdn documentation, bitmap.clone(rectangle, pixelformat) can throw outofmemoryexception if first parameter "outside of source bitmap bounds".

verify first parameter bitmap.clone; make sure rect entirely within bounds of image.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -