how to resize large number of images in a folder in c# windows application. I am using following code to resize images of my folders. If images are less than 1600 ( in number) then no proble but if images are more than 1600 then i am getting error. My code is given below:-
public static Image ResizeImage(string file, int width, int height, bool onlyResizeIfWider)
{
using (Image image = Image.FromFile(file))
{
// Prevent using images internal thumbnail
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
if (onlyResizeIfWider == true)
{
if (image.Width <= width)
{
width = image.Width;
}
}
int newHeight = image.Height * width / image.Width;
if (newHeight > height)
{
// Resize with height instead
width = image.Width * height / image.Height;
newHeight = height;
}
Image NewImage = image.GetThumbnailImage(width, newHeight,null,IntPtr.Zero);
return NewImage;
}
}