I’m using a TWAIN control to scan images, this works fine and I can scan an image and display it in pictureBox1. I’m struggling with adding multiple images to a stream and then using a Previous and Next button to step through them.
Can someone please help, my code below does not work, I’m now in a fog of confusion. Thanks
//The axTwain1_OnAcquire event runs on each scanned page.
private void axTwain1_OnAcquire(object sender, EventArgs e)
{
images = new List<Image>();
pageCount = pageCount + 1;
axTwain1.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + pageCount +".jpg");
FileStream stream = File.OpenRead(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + pageCount + ".jpg");
images.Add(Image.FromStream(stream));
pictureBox1.Image = System.Drawing.Bitmap.FromStream(stream);
}
private void btnNext_Click(object sender, EventArgs e)
{
index++;
if (index < 0 || index >= images.Count)
index = 0;
pictureBox1.Image = images[index];
int count = index + 1;
//labelCount.Text = "Showing " + count.ToString() + " of " + images.Count;
}
private void btnPrevious_Click(object sender, EventArgs e)
{
index++;
if (index < 0 || index >= images.Count)
index = 0;
pictureBox1.Image = images[index];
int count = index + 1;
}
You’re logic looks a bit screwy. In both the previous and next functions, you have the conditional statement:
For a next, your logic should look something like:
and for your previous:
So essentially, your functions should look like: