VintaSoft Twain .NET SDK Discussions
Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.
Board index < VintaSoft Twain < VintaSoft Twain .NET SDK Discussions
public AcquiredImage[] ScannedImages = new AcquiredImage[100];Everything seemed to be fine, until I found, that after a device change I cannot access any image from this array, that has been scanned from the previouly selected device. To make this easier to understand, I wrote 2 functions to show whatВґs causing the problem.
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];
Bitmap finalImg = new Bitmap(CurrentImage.GetAsBitmap(), MySize.Width, MySize.Height); <--- this line generates a NullReferenceException
}
I know, what a nullReferenceException tries to tell me, but the debugger shows, that CurrentImage (and due to that ScannedImages[0]) has a valid image oth the type "AcquiredImage".ScannedImages[1] = _device.AcquiredImages[Index];As soon, as _device ist closed, and another device opened, there is no chance to use ScannedImages[1] anymore.
public DeviceManager _deviceManager;
public Device[] _deviceList;
_deviceManager.Open();
Int32 DeviceCount = _deviceManager.Devices.Count;
_deviceList = new Device[DeviceCount];
....
Bitmap finalImg = new Bitmap(_deviceList[_activeDeviceIndex].AcquiredImages[Index].GetAsBitmap(true) ....
private void openDevice()
{
if (!_deviceIsOpen[_activeDeviceIndex])
{
try
{
_activeDeviceIndex = _deviceManager.Devices.CurrentIndex;
_deviceList[_activeDeviceIndex] = _deviceManager.Devices.Current;
_deviceIsOpen[_activeDeviceIndex] = true;
SubscribeToDeviceEvents();
showUIToolStripMenuItem.Checked = _deviceList[_activeDeviceIndex].ShowUI;
modalUIToolStripMenuItem.Checked = _deviceList[_activeDeviceIndex].ModalUI;
_deviceList[_activeDeviceIndex].AcquiredImages.Capacity = 20;
SetStateOfImageProcessingButtons();
}
catch (TwainDeviceManagerException ex)
{
MessageBox.Show(ex.Message, "Open device manager");
return;
}
}
}
This one seems to work :)