I want to show images with gps tags on form. User click on image than I show gps location from the image on statusbar. I loaded some image files(for example, 40) and get exception - OutOfMemory. File jpeg have size - 5Mb, after Image.FromFile disappear 50 Mb memory. Example, 1) run application - memory - 50Mb 2) select 5 image files(25Mb) - memory - 316Mb(!?) 3) click on image in ListView,rise event listView1_SelectedIndexChanged, show gps location - memory - 43Mb(GC did his good job)
How do I load images without big memory?
If I call
image.Dispose();
after
imageList1.Images.Add(image);
there is no images on Form
Code load images:
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
ofd.Filter = "Images (*.jpg, )|*.jpg";
ofd.Title = "Select files";
if (ofd.ShowDialog() != DialogResult.OK)
return;
ListPathFoto.Clear();
foreach (string f in ofd.FileNames)
{
ListPathFoto.Add(f);
}
imageList1.Images.Clear();
foreach (var oneFilePath in ListPathFoto)
{
var image = Image.FromFile(oneFilePath);
imageList1.Images.Add(image);
}
listView1.Clear();
listView1.View = View.LargeIcon;
imageList1.ImageSize = new Size(32, 32);
listView1.LargeImageList = imageList1;
for (int j = 0; j < imageList1.Images.Count; j++)
{
ListViewItem item = new ListViewItem
{
ImageIndex = j
};
listView1.Items.Add(item);
}