0

I am trying to display images in pictureboxes in C# windows form. There are many images, say 100s and their average size is about 1 MB. So I want to compress or decrease their size before they are loaded into the picturebox. Now it throws 'outofmemory exception'. Please how can I achieve this? Help me.

My code looks like

List<string> imgPaths = new List<string>();
foreach(string imgName in imgPaths)
{
  Image img = Image.FromFile(imgName);
  // I want to compress the image, but I don't know how to

  PictureBox picBox = new PictureBox();
  picBox.Image = imgCompressed;
  .....
  .....
}
FREAKYHUNTER
  • 301
  • 3
  • 15
  • did you try this [one](http://msdn.microsoft.com/en-us/library/bb882583(v=vs.110).aspx)? – spajce Feb 02 '14 at 08:36
  • @FREAKYHUNTER - you can resize the image before loading to the picturebox. See the answer of [this](http://stackoverflow.com/questions/6501797/resize-image-proportionally-with-maxheight-and-maxwidth-constraints) SO question for resizing sample code. – Junaith Feb 02 '14 at 08:57

0 Answers0