I'm trying to interface with a TWAIN-compliant multifunction printer and scanner, a Canon Pixma MG5750, from C# using the NTwain library. I'm writing a program to scan an image into an Image
object.
The scanner has to warm up before scanning the image; it displays the following popup while doing so:
Once this process has finished, it begins scanning the document.
While the program does work, the problem is that this warming up process sometimes takes far too long for no apparent reason, up to a few minutes. This problem never occurs when using Canon's own app, IJ Scan Utility, which uses TWAIN and displays the same dialog, but only for a few seconds.
Is there a TWAIN capability I can use to increase the speed of this warm up process? I've tried changing the ICapXResolution
and ICapYResolution
, but these only increase the speed of the actual scan after the warm up, not affecting the warm up itself.
My program is shown below. Note that it's a Console app, hence the use of ThreadPool
.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using NTwain;
using NTwain.Data;
using System.Drawing;
using System.Threading;
namespace TwainExample
{
class Program
{
[STAThread]
static void Main(string[] args)
{
ThreadPool.QueueUserWorkItem(o => TwainWork());
Console.ReadLine();
}
static void TwainWork()
{
var identity = TWIdentity.CreateFromAssembly(DataGroups.Image, Assembly.GetEntryAssembly());
var twain = new TwainSession(identity);
twain.Open();
twain.DataTransferred += (s, e) =>
{
var stream = e.GetNativeImageStream();
var image = Image.FromStream(stream);
// Do things with the image...
};
var source = twain.First();
Console.WriteLine($"Scanning from {source.Name}...");
var openCode = source.Open();
Console.WriteLine($"Open: {openCode}");
source.Enable(SourceEnableMode.NoUI, false, IntPtr.Zero);
}
}
}
It outputs:
Scanning from Canon MG5700 series Network...
Open: Success