I have problem with List<Image>
List<Image> _Images = new List<Image>();
int currIndex = 0;
private void btnAdd_Click(object sender, EventArgs e)
{
using (OpenFileDialog dialog = new OpenFileDialog())
{
dialog.Filter = "All Images|*.jpg;*.jpeg;*.png;*.bmp;*.gif";
if (dialog.ShowDialog() == DialogResult.Cancel)
return;
_Images.Add(Image.FromFile(dialog.FileName));
currIndex = _Images.Count - 1;
picBox.Image = _Images[currIndex];
}
}
private void btnNext_Click(object sender, EventArgs e)
{
if (currIndex + 1 >= _Images.Count)
return;
picBox.Image = _Images[++currIndex];
}
private void btnBack_Click(object sender, EventArgs e)
{
if (currIndex - 1 < 0)
return;
picBox.Image = _Images[--currIndex];
}
After i added two images to that list, i got this exception when i press on Back button btnBack_Click : Parameter is not valid.
why did it work when i first add the image picBox.Image = _Images[currIndex]; then when i try to get an image from index later, it gives me that exception?
Note: i didn’t use ImageList, because as i know, it has ImageSize which will be constant for all images.
so how would i get it work?
Update :
It worked now, when i changed List<Image> to List<Stream>
picBox.Image = Image.FromStream(_Images[--currIndex]);
Change your
List<Image>toList<Stream>Then it will work.