twain / twain-cs

A C# interface for TWAIN
167 stars 66 forks source link

Some requests for ShowImage 1) STS param, 2) Image Type param, 3) Metadata param (or combine 2 into 3) [sf#2] #6

Closed kolomiets closed 7 years ago

kolomiets commented 7 years ago

Reported by vin-finn on 2014-02-20 21:47 UTC Love this module. I'm using it in a Web based scanner service. I needed to modify ShowImage to send the STS param so that I would know the reason for the call into ShowImage when the bitmap is null. In my showimage callback I keep track of numpages scanned and if the a_bitmap is null, numpages is 0, sts != TWAINCSToolkit.STS.SUCCESS I generate an error message based on: if (sts == TWAINCSToolkit.STS.CANCEL)
{ TS_ProgressMsg = "Paper not loaded, job cancelled, please load paper"; } else { TS_ProgressMsg = "Job terminated with error: "+sts.ToString(); }

If numpages is >0 then I show a cancel message and I post the sts.ToString().

In addition to STS it would be very useful to know the image type that has been stored. I know where the images are stored since I set that location but the scanned image can be TIF, JPG or BMP, and I have to look in the folder to figure that out. It would be useful to be told the image type via a System.Drawing.Imaging.ImageFormat type of parameter.

I know I can take the bitmap, but I don't use that bitmap since I can't display the image at the time of the callback. The GUI has to query for status and upon discovery of a new image call for the image. So the ShowImage callback triggers the event, and later I access the image via the stored image. If it is appropriate to have two showimage types, one as an event without the image as a parameter and more notification information on just what was stored, that would be preferable. I extract metadata from the images and it would be very nice to be provided that metadata at callback time, rather than the image itself.

Thank you for such a great library. Vinnie

kolomiets commented 7 years ago

Updated by mlmcl on 2014-02-26 22:29 UTC

kolomiets commented 7 years ago

Commented by mlmcl on 2014-02-26 22:29 UTC I've added TWAINToolkit.STS to the ShowImage function, and a string to the filename (this value can be either a valid filename, null or "", depending on the transfer method, so be careful with it). The best use for the status is to examine its value when the Bitmap is null, this will reveal the reason the scan session ended.

Information on the file format for file transfers can be gleaned from a call to DG_IMAGE /DAT_SETUPFILEXFER / MSG_GET. Since the toolkit assigns names, it uses .tif and .jpg, so format identification can be done that way as well. ShowImage isn't called until after the toolkit is completely done with the image, so it's safe to copy, rename or even delete the file.

Information on the image itself should be obtained from a call to DG_IMAGE / DAT_EXTIMAGEINFO / MSG_GET or DG_IMAGE / DAT_IMAGEINFO / MSG_GET. It's not possible to anticipate all of the option for these calls, so that task is left to the application writer.

kolomiets commented 7 years ago

Updated by mlmcl on 2014-02-26 22:29 UTC