Giter Club home page Giter Club logo

twaindotnet's Introduction

twaindotnet

This project is based off the code from Thomas Scheidegger's excellent article on The Code Project: http://www.codeproject.com/KB/dotnet/twaindotnet.aspx

Also check out another alternative library: NTwain

twaindotnet Features

Page Related

  • Support for automatic document feeders.
  • Set the number of pages to scan.
  • Support for duplex scanning.
  • Automatic border detection support for scanners that support this capability.

Resolution Related

  • Support for custom scan resolution (in DPI).
  • Support for colour, grey scale and black and white scanning.

User Interface Related

  • The ability to show the manufacturer's user interface.

TWAIN Resources

Tested Scanners

Brother

  • Brother DCP 7020

Canon

  • Canon !CanoScan FB636U
  • Canon !CanoScan 8000F
  • Canon PIXMA MP280

Epson

  • Epson Stylus Office TX300F
  • Epson Perfection V10

Fujitsu

  • Fujitsu FI-4120
  • Fujitsu FI-6130
  • Fujitsu FI-6410

HP

  • HP !ScanJet 5370C.
  • HP Color !LaserJet CM2320fxi MFP
  • HP DeskJet 2130

Kodak

  • Kodak i1220

Mustek

  • Mustek 600USB

Panasonic

  • Panasonic KV-S1025C

Plustek

  • Plustek OpticSlim 550

Ricoh

  • Ricoh Aficio MP 161

Samsung

  • Samsung M288x Series 3.31

twaindotnet's People

Contributors

andreyakinshin avatar dguidi avatar edonosotti avatar ijourneaux avatar jknipp avatar jonasingvar avatar lukas06 avatar mcdon-ron avatar peters avatar ramsesmartinez avatar tmyroadctfig avatar tylerdm avatar unholyhub avatar vincenormand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twaindotnet's Issues

How to set ScanSettings with multiple attributes

Hi everyone,

I m working with Canon Imageformula DR-C130L on a WPF C# project. I want to set scan settings with custom attributes. Please see the below image:
error

I am getting error when below settings are apply like "Do nothing if the data source does not support the requested capability".

This is custom screen I have designed:
error1

Some attributes are not applied like page size, page orientation, page auto rotate, scanning side simplex etc.

I have tried many times, Please help me.

resizing TransferImageEventArgs args

Hi!

I scan images with 8bit grayscale, this is the setting in Twain UI.
But in my code after each page
args.Image.Pixelformat is set to Format32bppArgb.

How can i change this Pixelformat?

Greetings,
Ulrich

DsImageLayout.GetDefault error

What steps will reproduce the problem?

  1. Add setting in ScanSetting ScanSettings settings2 = new ScanSettings { ShowTwainUI = false, ShowProgressIndicatorUI = true, Area = new AreaSettings(TwainDotNet.TwainNative.Units.Inches, 0f, 0f, 6f, 11.5F) };
  2. Selecting scanner source
  3. _twain.StartScanning(settings2)

What is the expected output? What do you see instead?
Expected proper scanning with 11.5-inch height

This happens when AreaSetting is added in the scan setting. Without AreaSetting it works fine.

Error Opening Data Source

Hi,

I faced an issue in "TestAppWpf", Saying "error opening data source". Following are the steps to reproduce the issue:

  1. Select scanner with "ShowTainUI = true" and start scan
  2. When Scanner settings screen displays say "Cancel",
  3. try to start the scan again error pop ups: Saying "error opening data source".

If user says cancel in any stage, it should cancel the job and should be ready to re scan.

Please let me know if there is any fix for this.

Thanks and Regards,
Saira

Trying to set 1200 DPI on Epson scanner

I am trying to set 1200 DPI on my Epson Perfection V550 scanner. I end up getting a TWAINException indicating "TwainDotNet.TwainNative.ConditionCode.CapabilitySequenceError". The scanner is certainly capable of 1200pi (as well as even high dpi values).

I am using TWAINDotNet from VB.Net 2010

Window immediately pops behind other windows on launch.

The instant I add "new Twain(new WinFormsWindowMessageHook(this));" to my winform, that form falls out of the foreground when it starts up. It ends up jumping behind other windows and I have to click on it or its start bar icon to bring it forward again. I'm not sure what the issue since the message prefilter isn't called until a scan, but it is definatly related to this line of code.

using twaindotnet in console application

hi
i want to use the library in a console application. i implemented the IWindowsMessageHook and used process handle for intPtr handle. but after starting the scan and when scanner finishes the scan , the "TransferImage" and "TransferComplete" never fires.is there something i can do ?

Capability - Automatic Rotate unsupported

When I set the scanner setting of 'Automatic Rotate', the image(s) won't scan, and it gives an error, stating that 'Unsupported capability, Automaticrotate'. The error is thrown from the Capability class, in the GetBasicValue() method.

capability1

When the error occurs:
The parameters of the one value field are TwainType: Bool; Value: 0;
The twainCapability is 'TwainDotNet.TwainNative.Capabilities.Automaticrotate'
The conditionCode is 'TwainDotNet.TwainNative.ConditionCode.CapabilityUnsupported'
The other scanner settings, such as 'Use ADF', 'Use UI', and 'B & W' are working successfully.

The scanner is a 'Canon DR-G1130 TWAIN 1.123 (32-32)'.
Does anyone have thoughts on troubleshooting steps or on what may be the cause of the issue?

Hot to set the number of pages to scan.

I'm using an officejet J4660 all-in -one from HP everything works fine, but at this time I have not found an option that lets me select the amount of pages to scan, the main target of my project is scanning 2 or more pages and save them in a single PDF document, can you explain a little how to do this? thanks

Please,Help!!!Hot to use Use dual memory settings?

This message come form China.I use twaindotnet coding my exe.But,I don't know how to set twaindotnet use dual memory from ScanSettings not from Use UI.Thank you for your answer.This libary is the best I Have seem.

NuGet

Are you planning to push you library to NuGet?

How to Set Dpi ?

Hi everyone,
I m working with Fujitsu fi-65F on a C# project. I want to get image with max DPI (600).
how to do that ?

Error: Could not load file or assembly

Hi, I'm getting this error

An error occurred creating the form. See Inner.Exception for details. Th error is: Could not load file or assembly 'TwainDotnet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d3cd6e1539fa8c71' or one of its dependencies. An attempt was made to load a program with an incorrect format.

its a new project, not the sample..my project is set to .Net Framework 4, platform to AnyCPU...when i try to change the platform target to AnyCPU of TwainDotNet & TwainDotNet.WinFroms..the above exception is gone, but there will be another error on the DataSourceManager BadImageFormatException on TwainDotnet

Twain Resources

The TWAIN Resources appears to unavailable.

  • TWAIN 2.0 Spec
  • TWAIN header file

Is there any optional link?

how to get 1 bit tif?

hi!
thanks for the excellent library!
how do i set TwainDotNet to scan 1 bit depth tif images?
at the moment even if i set the color to B&W, it still saves at 24bit
thank you very much!
p.s. im using TDN in WPF, if it matters.

issue with x64 windows!

Is this source run on (.net 4.0) windows x64 platform? when I run the source it throws me the below error: "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B"
Have anyone tried this? thanks.

Issue on Windows 8.1 x64

Hello,

I'm using this library in a bigger project and since now everything was fine. But now, we've changed our OS to Win 8.1 x64 and things get complicated. We use a Fujitsu fi6130z, which has worked fine in the past. Now, if I want to trigger a scan, I get an AccessViolation-Exception, when the DataSource is trying to close (for example, I try to select source in the test app).

Twain32Native.DsUserInterface(_applicationId, SourceId, DataGroup.Control, DataArgumentType.UserInterface, Message.DisableDS, userInterface); gets a "failure"-Result, and I cant figure out why. Windows 7 and XP don't have any problems there. My guess was, that there are any problems with access privileges under Win8.1, which are set to other default values than Win 7. But I don't know, which ones could it be. Other tools like IrfanView are working fine with TWAIN, so I'm not really sure, what I sould do now.

And then there is no activity on this project for 6-12 months, so my hope is going away, while writing this here. Is there any chance to get some informations about this?

Thanks

Error on initialization if invalid data source selected.

I have a rogue scanning driver which likes to mess with the default selected scanner every time I take an image. I'm not sure of what is actually happening, but what ends up happening is that TWAIN is unable to detect the default scanner. On other scanning programs this shows up as an error when I try to acquire an image, but I can go to the device selection dialog and select it again.

However, TwainDotNet initialization will fail if this happens, because on method

public static DataSource GetDefault(Identity applicationId, IWindowsMessageHook messageHook)

which is called on initialization, it will throw an exception if it can't detect the scanner.
(I get the condition code MaxConntions which is not too useful).

So far I've been able to 'hack' it by just commenting the throw clause and letting TwainDotNet continue initialization, and in my simple use case this hasn't caused problems so far, though I believe some more work has to be done to adapt TwainDotNet in case there's no default scanner.

Thanks, throwaway1290304032.

Support For Film Scanner

I was wonder how difficult it might be to add in support for selected DocumentType (in Epson terms) where the 2 choices would be Reflective and Film?

Correct way to set capability gamma?

I try to get and set gamma capability for my DS.
I use:

int gamma = 10;
var cap = new Capability(Capabilities.Gamma, TwainType.Fix32, _applicationId, SourceId);
var basicCapResult = cap.GetBasicValueCurrent();
if (gamma != basicCapResult.Int32Value)
    Capability.SetBasicCapability(Capabilities.Gamma, gamma, TwainType.Fix32, _applicationId, SourceId);

The value of current capability is always 858980354, and setting the value will fail. Twain32Native.DsCapability() throws an exception at protected void SetValue<T>(T value) in Capability.cs.

Any suggestions?

Parameter is not valid

Hi,

In working with an Epson S-9000 scanner to scan banking checks we've run into a problem wherein after scanning ~300 or so, we'll get an exception (Parameter is not valid.) thrown from BitmapRender.RenderToBitmap on the sixth line: IntPtr hdc = graphics.GetHdc();

This would seem to indicate that the memory is not being collected over time but it looks like all of the appropriate precautions to dispose of the BitmapRender and the associated memory from the device were taken. As I'm not familiar with the twain_32 dll I was hoping you could provide some more assistance.

Kevin W

Only scans about 1/4 of the flatbed with some canon scanners

With some canon scanners, it only scans about 1/4th of the entire flatbed. That 1/4th area is blown up and takes up the entire page. I tried the test Wpf App that comes with this project and it has the same issue.
I'm using Canon PIXMA MP 280, BTW. I have a lot of scanners to test with. It's just the canon scanner that has this issue.

Example : (this is just the bottom right 1/4th of the page that is getting scanned)
ab

Automatically close user interface(ui) after image scan complete

hi i m using hp scan-jet 2400 and hp scan software user interface, to check image processing. but after scan complete it will manually click to finish button and transfer image from hp scan UI to Twaindotnet app. there any way to automatically close hp scan UI after scan complete and transfer image to Twaindotnet.

Any help in this Solution is greatly appreciated.

Image is not captured if (_bitmapInfo.XPelsPerMeter == 0 || _bitmapInfo.YPelsPerMeter == 0)

Hi,

In one of my scanning devices, I was getting no image transferred when I sent the scan request through TwainDotNet, even though the device itself did the scanning.

After some guesswork I found the offending line:

bitmap.SetResolution(PpmToDpi(_bitmapInfo.XPelsPerMeter), PpmToDpi(_bitmapInfo.YPelsPerMeter));

It looks like my scanning device is setting _bitmapInfo.XPelsPerMeter = 0 and _bitmapInfo.YPelsPerMeter == 0, so the call to SetResolution fails with 'Invalid Parameter'.

Fixing it is trivial by skipping the call or setting some sensible default if those fields are set to zero.

Thanks, throwaway1290304032

Reset Scanner

Hi! Is there a way to reset a scanner if it hangs? I have tested a EPSON Workforce 7500DS with twaindotnet, sometimes the scanner freezes after large scanjobs(25 pages) and it takes a long time to get it working again. Turning the scanner off / on doesn't help. Turning off the PC doesn't help.
Waiting for a long time (10-30min) helps....

how to set custom page size? please give ans

_settings = new ScanSettings();
_settings.Page = new PageSettings();
_settings.Resolution = new ResolutionSettings();
_settings.UseDocumentFeeder = useAdfCheckBox.Checked;
_settings.ShowTwainUI = useUICheckBox.Checked;
_settings.ShowProgressIndicatorUI = showProgressIndicatorUICheckBox.Checked;
_settings.UseDuplex = useDuplexCheckBox.Checked;
_settings.Resolution.Dpi = 800;
_settings.Page.Size = TwainDotNet.TwainNative.PageType.MaxSize;

                   **hello i want to set custom page size like (1527,800)**

Using twaindotnet in a thread...

I am really stuck on utilizing this codebase because in my case, interaction with the scanner must be on a separate thread from my MDI style windows form application.

My form app that starts a background thread (BGthread). The BGthread creates a System.Collection.Concurrent.BlockingCollection and processes the commands that get added to the collection. This BGthread uses the TwainDotNet classes to interact with the downstream scanner.

My MDI app puts a command into the collection monitored by the BGthread. For example, an instance of command would be a command to instantiate the TwainDotNet.Twain class. A follow-up instance of command would be to execute TwainDotNet.Twain.StartScanning(). And so on…

My issue is that the TwainDotNet.WinFroms.WinFormsWindowMessageHook.PrefilterMessage() method is not ever executed. The scanner behavior at this point is that the motor starts up as if to engage the document feeder. However, the actual scan behavior never starts up. The scanner holds in this state for a few seconds and then the motor shuts off and goes into an idle state. Additionally, the MDI app is in a non-responsive state (maybe because the ImageHasTransferred/ScanningComplete events are not posted).

Suspect that this behavior is because TwainDotNet.Twain.StartScanning() is executed on my BGthread -not on my MDI app thread. When I remove the threading, things are working successfully.

Very grateful for any help, suggestions and especially answers!

Two Sides

Well, for scanning a single side of the page is working perfect.

I tested on a Lexmark MX711 and Fujitsu fi-6140

But when is for scanning the two sides of the page (i think it would be the duplex option = true) it scan like default option.

Any hint what it could be or maybe how we fix it?

Memory problems

I'm trying to create a bridge application (external exe) to allow the acquisition of images from a 64bit application by a 32bit twain driver.
My first problem is that the acquired image is very big (7700x7200 pixels) and the size is about 166MB.
The problem is that during the full scan sequence the memory reach 700MB and more and I'm not able to save the image on disk (GDI+ raise a generic exception but I'm sure that it is related to the memory).
I don't know it there is a possibility to reduce this memory usage, what I have seen is that there are three allocation of 166MB: the acquisition made by the twain driver (DsImageTransfer), the render of the bitmap (RenderToBitmap), and the last is in my code, the convertion in a buffer to allow the send to the main application.

I have found a small workaround by moving the call of the event TransferImage (in the DataSourceManager) outside the block using (using (var renderer = new BitmapRenderer(hbitmap))) in this way the framework is able to reuse the memory allocated with the RenderToBitmap method.
The code changed is in the DataSourceManager.cs at line 235:

                    TransferImageEventArgs args;
                    using (var renderer = new BitmapRenderer(hbitmap))
                    {
                        args = new TransferImageEventArgs(renderer.RenderToBitmap(), pendingTransfer.Count != 0);
                    }
                    TransferImage(this, args);
                    if (!args.ContinueScanning)
                        break;

Any other suggestions are appreciated

Carrier Sheet

Hi,

I m trying to set the capability but it doesn't work, maybe a limitation of twain32.dll used by the lib ?
with the twain tool, if i do :
DG_CONTROL DAT_CAPABILITY MSG_SET
with
0xF00C,TWON_ONEVALUE,TWTY_BOOL,1
it works.

I tried with the lib but no luck so far even with changing the struct from short to long because 0XF00C is not a short number...

thanx for any guidance...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.