I´m currently writing a little scanning app, that´s supposed to be used in our warehouse. A typical szenario will be, that the users scan <n> pages of documents, and in some cases additionally some photos for any goods with damages. All together these images build a document set to be stored as a multipage tiff within our archive.
My idea was, that the user can retrieve the photos from the camera by twain as well. At the same time I´m showing all scanned images as 20% previews on a scrollable panel at the left side of the window. Selecting one of those preview images by clicking on it´s pic box displays a detailed image (100%) in a picturebox on the right side of the window. At any time it must be possible to click one of the previews and e.g. use functions as rotate or deskew.
Since the user can change the scan device as often as he wants, the images within the device object will be lost on any of those changes, while I still need access to any original und unscaled Acquired Images to display it in the detailed pic box or to rotate it. Due to that I decided to store all AcquiredImages with an array:
Code: Select all
public AcquiredImage[] ScannedImages = new AcquiredImage[100];
The following code is based on the assumption, that ScannedImages[0] is e.g. a document from a canon doc scanner, while ScannedImages[1] is a photo retrieved by twain from an iPhone -> http://www.bosfood.de/Pidi/TwainApp.jpg
All code like the usage of finalImg has been removed, to get it to the point. I just load ScannedImage[1] from my array, make a 2.5 second pause and then try to load ScannedImage[0] (which came from another device) by "getAsBitmap" from my array:
Code: Select all
private void ImageTest()
{
Size MySize = new Size(pictureBoxDetailed.Width, pictureBoxDetailed.Height);
AcquiredImage CurrentImage = ScannedImages[1];
Bitmap finalImg = new Bitmap(CurrentImage.GetAsBitmap(), MySize.Width, MySize.Height);
Application.DoEvents();
System.Threading.Thread.Sleep(2500);
ImageTest2();
}
private void ImageTest2()
{
Size MySize = new Size(pictureBoxDetailed.Width, pictureBoxDetailed.Height);
AcquiredImage CurrentImage = ScannedImages[0];
[b] Bitmap finalImg = new Bitmap(CurrentImage.GetAsBitmap(), MySize.Width, MySize.Height); <--- this line generates a NullReferenceException[/b]
}
Since the device object, the image within ScannedImages[0] came from, is not existing anymore, there seems to be a reference to that non existing device object as part of the acquired image?
If I´m right, this brings up the final question, how one would handle AcquiredImages from different devices with on Windows form?
Thanks in advance for any help or hint.
Michael