|
PDF sharp was really easy to use for this. It could take a bmp and turn it into a physical pdf or a memory stream to send along.
|
|
|
|
|
could you please specify details on how to do this? or a sample? 
|
|
|
|
|
Hello, has anyone managed to get the possible resolutions? I don't know how to define TwCapability to alloc space according to the length of the resulting enum, nor how to read the values from the enum.
Has anyone a hint or sample how to read such capabilities?
Greetings Jörg
|
|
|
|
|
how to make scan files with multiple feeder and we give a default name
example 10 page
with name scan1 and automatically when scan name is scan1,scan2,scan3,etc
thanks so much
zimmy gurning
|
|
|
|
|
Hi,
I think I'm being a right thicko here and would appreciate some advice.
I'm trying to determine whether or not there is paper currently loaded in the feeder during the during the Aquire method so I've added CAP_FEEDERLOADED (0x1003) to TwainDefs and the following code to the Aquire method. I can't seem to figure out how to retrieve the value.
Thanks for your help,
Chris
TwCapability capFeederLoaded = new TwCapability(TwCap.CAP_FEEDERLOADED);<br />
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.GetCurrent, capFeederLoaded);<br />
if (rc != TwRC.Success)<br />
{<br />
CloseSrc();<br />
MessageBox.Show("FEEDERLOADED Failed");<br />
return false;<br />
}<br />
else<br />
{<br />
<br />
<br />
}
|
|
|
|
|
I've worked this one out. Here is the code, hope it helps someone else:
Thanks to spike on www.twainforum.org
Chris
TwCapability capFeederLoaded = new TwCapability(TwCap.CAP_FEEDERLOADED);<br />
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Get, capFeederLoaded);<br />
if (rc != TwRC.Success)<br />
{<br />
CloseSrc();<br />
MessageBox.Show("FEEDERLOADED Failed");<br />
return false;<br />
}<br />
else<br />
{<br />
<br />
IntPtr pv = Twain.GlobalLock(capFeederLoaded.Handle);<br />
bool bFeederLoaded = (0 != (short)Marshal.ReadInt32(pv, 2));<br />
Twain.GlobalUnlock(capFeederLoaded.Handle);<br />
Twain.GlobalFree(capFeederLoaded.Handle);<br />
<br />
if (!bFeederLoaded)<br />
{<br />
TwCapability capFeederLoaded = new TwCapability(TwCap.CAP_FEEDERLOADED);<br />
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Get, capFeederLoaded);<br />
if (rc != TwRC.Success)<br />
{<br />
CloseSrc();<br />
MessageBox.Show("FEEDERLOADED Failed");<br />
return false;<br />
}<br />
else<br />
{<br />
<br />
IntPtr pv = Twain.GlobalLock(capFeederLoaded.Handle);<br />
bool bFeederLoaded = (0 != (short)Marshal.ReadInt32(pv, 2));<br />
Twain.GlobalUnlock(capFeederLoaded.Handle);<br />
Twain.GlobalFree(capFeederLoaded.Handle);<br />
<br />
if (!bFeederLoaded)<br />
{<br />
CloseSrc();<br />
MessageBox.Show("NO PAPER DETECTED");<br />
return false;<br />
}<br />
<br />
}<br />
}<br />
<br />
}
modified on Monday, February 14, 2011 9:42 AM
|
|
|
|
|
Thank you very much Chris Shaw. This is help me to avoid high memory usage while scanning more than 20 documents in a single scanning.
|
|
|
|
|
Hello guys ,
i have developed application which detect scanner and i do some business process now problem is my application can detect network scanner as i use same library which .Net master made ,but what is i want to detect scanner which is in VPN in other country.I am connected to VPN Scanner and install proper driver for scanner as well but my application cant detect that VPN Scanner..What is the problem what else need to detect remote scanner ? please help me .
|
|
|
|
|
Hi,
I want to show driver interface to capture images.
DSuserif( appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif ) gives success return without waiting for the driver interface to capture image.
Please advice,
Thanks in advace
|
|
|
|
|
I want to access network scanner from Twain, i unable to access the scanner from client machine where i run the twain application
|
|
|
|
|
I want to pass code control scanning, but not through the scan button in UI to scan
|
|
|
|
|
help ,I want to control scan in code, but not show in the UserInterface .
|
|
|
|
|
If you have Library CtwainDefs, there is a Class TwUserInterface. In your form create Object of TwUserInterface and then you can access to ShowUI and ModalUI
|
|
|
|
|
Hello,
on a Windows 7 system (64 bit) I have a problem with this code in TwainGui:
01 public void Acquire()
02 {
03 TwRC rc;
04 CloseSrc();
05 if( appid.Id == IntPtr.Zero )
06 {
07 Init( hwnd );
08 if( appid.Id == IntPtr.Zero ) return;
09 }
10 rc = DSMident( appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds );
11 if( rc != TwRC.Success )
12 return;
...
At line 10 the application crashes. I use Visual Studio 2010 Ultimate. I have tested all available .NET Framework 2.0, 3.5 and 4 and all plattform configurations. The orginal binary of TwainGui works perfectly. What's wrong?
Best regards
|
|
|
|
|
HI,
you must modify in TwainDefs.cs this line code :
[StructLayout(LayoutKind.Sequential, Pack=2, CharSet=CharSet.Ansi)]
internal class TwIdentity
{
public uint Id;
Then you must modify in TwainLib.cs all refercede line example :
if (appid.Id == 0)
I made this change and now work fine also in windows 7 64 bit.
I hope this help
best regard
daniela
|
|
|
|
|
I tried this but i have an error in the line
public void Init(IntPtr hwndp)
{
Finish();
TwRC rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp); //<--- HERE!
//the error is BadImageFormatException
{"Tentativo di caricare un programma con un formato non corretto. (Eccezione da HRESULT: 0x8007000B)"}
Thanks a lot
liffo
|
|
|
|
|
I am trying to write the scanned file to disc automatically after the scan is completed. My problem is writing the IntPtr to a FileStream. I can’t seem to get the right sequence of what needs to be done. Any help in pointing me in the right directions would be appreciated.
|
|
|
|
|
Hello, if someone can help me! I am trying to catch a exception when device is not found, I tried with try and catch block, when device is connected everything is working fluently but when device is not connected program freezes. With Wia there is exception when device is not connected, but I can't find how to solve this with twain. If someone know how to fix this I would be regardless.
|
|
|
|
|
Hi everyone,
I solved the puzzle. This is the code contains duplex, pixeltype, deskew, scan ahead, border detect, resolution.
It works successfully.
For Acquire method (TwainLib) :
// MAIN CAP AND MULTI SCAN
TwCapability cap = new TwCapability(TwCap.XferCount, -1);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);
if (rc != TwRC.Success)
{
CloseSrc();
MessageBox.Show("MAIN CAP FAILED");
return;
}
// DUPLEX
TwCapability capDuplex = new TwCapability(TwCap.CAP_DUPLEXENABLED, 1, true);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capDuplex);
if (rc != TwRC.Success)
{
CloseSrc();
MessageBox.Show("DUPLEX FAILED");
return;
}
//// 0 = BW | 1 = Gray | 2 = Colour
TwCapability capPixelType = new TwCapability(TwCap.IPixelType, 1, TwType.UInt16);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capPixelType);
if (rc != TwRC.Success)
{
CloseSrc();
MessageBox.Show("PIXEL TYPE FAILED");
return;
}
// BORDER DETECTION
TwCapability capBorder = new TwCapability(TwCap.ICAP_AUTOMATICBORDERDETECTION, 1, TwType.UInt16);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capBorder);
if (rc != TwRC.Success)
{
CloseSrc();
MessageBox.Show("BORDER DETECT FAILED");
return;
}
//// Set the X resolution
TwCapability capResX = new TwCapability(TwCap.ICAP_XRESOLUTION, 100, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResX);
if (rc != TwRC.Success)
{
CloseSrc();
MessageBox.Show("XRES FAILED");
return;
}
//// Set the Y resolution
TwCapability capResY = new TwCapability(TwCap.ICAP_YRESOLUTION, 100, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResY);
if (rc != TwRC.Success)
{
CloseSrc();
MessageBox.Show("YRES FAILED");
return;
}
// DESKEW
TwCapability capDeskew = new TwCapability(TwCap.ICAP_AUTOMATICDESKEW, 1, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capDeskew);
if (rc != TwRC.Success)
{
CloseSrc();
MessageBox.Show("DESKEW FAILED");
return;
}
For TwCapability internal class (TwainDefs):
internal class TwCapability
{ // TW_CAPABILITY
public TwCapability(TwCap cap)
{
Cap = (short)cap;
ConType = -1;
}
public TwCapability(TwCap cap, short sval)
{
Cap = (short)cap;
ConType = (short)TwOn.One;
Handle = Twain.GlobalAlloc(0x42, 6);
IntPtr pv = Twain.GlobalLock(Handle);
Marshal.WriteInt16(pv, 0, (short)TwType.Int16);
Marshal.WriteInt32(pv, 2, (int)sval);
Twain.GlobalUnlock(Handle);
}
public TwCapability(TwCap cap, short sval, TwType twType)
{
Cap = (short)cap;
ConType = (short)TwOn.One;
Handle = Twain.GlobalAlloc(0x42, 6);
IntPtr pv = Twain.GlobalLock(Handle);
Marshal.WriteInt16(pv, 0, (short)twType);
Marshal.WriteInt32(pv, 2, (int)sval);
Twain.GlobalUnlock(Handle);
}
~TwCapability()
{
if (Handle != IntPtr.Zero)
Twain.GlobalFree(Handle);
}
public TwCapability(TwCap cap, short sval, bool blnType)
{
Cap = (short)cap;
ConType = (short)TwOn.One;
Handle = Twain.GlobalAlloc(0x42, 6);
IntPtr pv = Twain.GlobalLock(Handle);
Marshal.WriteInt16(pv, 0, (short)TwType.Bool);
Marshal.WriteInt32(pv, 2, (int)sval);
Twain.GlobalUnlock(Handle);
}
public short Cap;
public short ConType;
public IntPtr Handle;
}
For Twcap ( TwainDefs) :
internal enum TwCap : short
{
XferCount = 0x0001, // CAP_XFERCOUNT
ICompression = 0x0100, // ICAP_...
IPixelType = 0x0101,
IUnits = 0x0102,
IXferMech = 0x0103,
CAP_AUTOSCAN = 0x1010,
CAP_DUPLEXENABLED = 0x1013,
ICAP_XRESOLUTION = 0x1118,
ICAP_YRESOLUTION = 0x1119,
ICAP_SUPPORTEDSIZES = 0x1122,
ICAP_AUTOMATICBORDERDETECTION = 0x1150,
ICAP_AUTOMATICDESKEW = 0x1151
}
|
|
|
|
|
can you tell me how get the capability of the scanner?
Although i know how to get the desired Item , but I don't know how to read the value.
|
|
|
|
|
Hi guys, I'm in the process of creating a simple wrapper class based on NETMaster's code. I'm having a lot of trouble following the code though.
You can follow a thread I'm writing on as I work on the project here:
http://www.dreamincode.net/forums/topic/203020-c%23-open-source-twain-wrapper/
I can't understand how to implement the code correctly so it returns a System.Drawing.Image.
I was wondering if an expert can come in and shed some knowledge. If we can build a decent wrapper class for this a lot of developer world wide will benefit. I kind of regret that NETMaster mixed GUI with core functionality, but at least he gave us a head start!
Please let me know if you'd like to help! Send me an email at stapia.gutierrez [AT] gmail [DOT] com
Hopefully we can create something recognized world wide!
|
|
|
|
|
Hello,
I used the code from the example. My windows form application can scan directly inside the code and save images to local path successfully, but I've a major problem about this scanning process. I have to set pageSize,dpi,scanning side,deskew vs. settings inside the code.
I read all the messages at this forum but I couldn't figure out how to set these settings. For example someone said that we can add the code below for the resolution setting.
I added "IXResolution=0x1118" under the TwCap and also created a overload for TwCapability. When I try this code or similar codes like this, I am getting an failure from "rc". Also there is a capability order for these settings but I couldn't figure out. Can anyone send me a working code with these settings ?
TwCapability capResX = new TwCapability(TwCap.IXResolution, 100, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResX);
if (rc != TwRC.Success)
{
CloseSrc();
MessageBox.Show("IXResolution");
return;
}
|
|
|
|
|
Can you Please post Your Scan and save image code to localpath directly.
I am searching from last few days .please post this code to tiru.jogu123@yahoo.com
|
|
|
|
|
Hi,
Is possible compile this on x64? I know that it throw exception BadImageFormatException because twain_32.dll is only for x86. But what if I use TWAINDSM.dll? I try it. If I compiled it on x86, everything is ok, but it I compiled it on x64 it doesn't throw any exception but it doesn't work too.
I need compile my application on x64. Any idea?
|
|
|
|
|
Hi,
When I just download the .exe from this article it works fine. But when I compile the source code, it compiles fine, but when I try to run it stops at the following line (ln 59 TwainLib.cs):
TwRC rc = DSMparent( appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp );
And the output shows:
The thread 'vshost.LoadReference' (0x1730) has exited with code 0 (0x0).
'TwainGui.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Users\xxxxx\Desktop\twaingui_src\TwainGui\bin\Debug\TwainGui.exe', Symbols loaded.
A first chance exception of type 'System.BadImageFormatException' occurred in TwainGui.exe
'TwainGui.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[2472] TwainGui.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[2472] TwainGui.vshost.exe: Managed (v2.0.50727)' has exited with code 0 (0x0).
It is working on Windows 7 32 bit, I can compile and run.
I tryed to download and install both 32 and 64 bits versions found in www.twain.org, compiled only to 32 bit, tryed to change the reference to twain_32.dll to twain.dll from dllimport, since both dlls exists, but it still doesn´t work.
Thank you,
Edgar
|
|
|
|
|