This maybe in the wrong section but it is to do with Twain and the WPF viewer.
I am moving from the older winforms viewer in V10 to the new WPF viewer in V11. I use code very similar to the winforms sample application for TWAIN capture.
What I am seeing is that if I try to preview the image after TwainAcquireToGdPictureImage the image doesn't show and something in TWAIN gets corrupt and the application loops continously without getting any more images.
Has anyone else come across this?
Here is some code if it helps
Code: Select all
protected GdPicture11.WPF.GdViewer _viewer = new GdPicture11.WPF.GdViewer();
do
{
if (_pictureImaging.TwainOpenDefaultSource(_windowHandle))
{
InitScanConfig();
Func<bool> doScanning = () =>
{
bool notBroken = true;
do
{
_viewer.ReleaseGdPictureImage(_currentImage);
_currentImage = _pictureImaging.TwainAcquireToGdPictureImage(_windowHandle);
if (_currentImage != 0)
{
ApplyImageFilters();
// THIS IS THE PROBLEM AREA
if (AppSettingsViewModel.Instance.PreviewImage)
{
_viewer.DisplayFromGdPictureImage(_currentImage);
}
//END PROBLEM AREA
imageCount++;
string filenum = scanningFolder + string.Format("{0:D9}", imageCount);
switch (imt)
{
case ImageTypes.JPG:
filenum += ".jpg";
break;
case ImageTypes.PDF:
filenum += ".pdf";
break;
case ImageTypes.TIF:
filenum += ".tif";
break;
}
if (File.Exists(filenum))
{
if (MessageBox.Show(@"File already exists click OK to overwrite or cancel to stop scanning", @"Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
{
notBroken = false;
break;
}
}
switch (imt)
{
case ImageTypes.JPG:
_pictureImaging.SaveAsJPEG(_currentImage, filenum, AppSettingsViewModel.Instance.JPGQuality);
break;
case ImageTypes.PDF:
_pictureImaging.SaveAsPDF(_currentImage, filenum, false, "", "", "", "", "");
break;
case ImageTypes.TIF:
if (tiffCompression == TiffCompression.TiffCompressionCCITT3 || tiffCompression == TiffCompression.TiffCompressionCCITT4)
_pictureImaging.ConvertTo1Bpp(_currentImage);
_pictureImaging.SaveAsTIFF(_currentImage, filenum, tiffCompression);
break;
}
var dvm = new DocumentViewModel(filenum);
var fi = new FileInfo(filenum);
dvm.CreationDate = fi.CreationTime;
dvm.Filesize = (ulong)fi.Length;
_scannedImages.Add(dvm);
_pictureImaging.ReleaseGdPictureImage(_currentImage);
}
else
{
notBroken = false;
break;
}
}
while (Convert.ToInt64(_pictureImaging.TwainGetState()) > Convert.ToInt64(TwainStatus.TWAIN_SOURCE_ENABLED));
return notBroken;
};