List <image exclusion> Parameter is invalid. "
I have a 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 this list, I got this exception when I click the back button btnBack_Click
: Parameter is not valid.
why it worked when I first added the picBox.Image = _Images[currIndex];
and then when I try to get the image from the index later, does it give me this exception?
Note: I did not use ImageList because, as I know, it has ImageSize, which will be constant for all images.
so how can i make it work?
Update:
Now it worked when I changed List<Image>
to List<Stream>
picBox.Image = Image.FromStream(_Images[--currIndex]);