|
Hello,
Can anyone show me the way, how i can access Client side Scanner From asp.net page.
I will be glad to receive some example code or advice!
You can also send solutions on my email: email2jasthi@yahoo.com
Thanks in advance!
|
|
|
|
|
Hi,
can anyone tell me, how I can get a list of all resolutions, the scanner supports?
Or at least the valid range or something like that, so that I can display possible values dynamically in a combobox...
It's very urgent!!!
Thanks!
|
|
|
|
|
I can't praise this article enough. Great job NetMaster.
One thing I can't get my head round is how to retrieve the correct values from the ItemList property of the TW_ARRAY and TW_ENUMERATION classes.
What I'm looking to do is query the CAP_SUPPORTEDCAPS capability (populating a TW_ARRAY class) allowing me to know in advance whether I need bother check for capabilities such as CAP_DEVICEONLINE.
Here's what I've done.
1. Created a TwArray class, implementing GetUInt16Array() which I've taken from elsewhere in this forum
[StructLayout(LayoutKind.Sequential, Pack=2)]<br />
internal unsafe class TwArray<br />
{ <br />
public ushort ItemType = 0;<br />
public uint NumItems = 0;<br />
public byte ItemList; <br />
<br />
public unsafe ushort[] GetUInt16Array()<br />
{<br />
ushort[] result = new ushort[NumItems];<br />
<br />
fixed (byte* pSrc = &ItemList)<br />
{ <br />
byte* ps = pSrc;<br />
<br />
for (uint n =0 ; n < NumItems ; n++)<br />
{<br />
result[n] = (ushort)Marshal.ReadInt16((IntPtr)ps);<br />
ps += sizeof(ushort);<br />
}<br />
}<br />
return result;<br />
}<br />
}
2. Modified the TwCapability constructor and added a GetTwArray class.
public TwCapability( TwCap cap, TwOn on_type, TwType type, int val )<br />
{<br />
Cap = (short) cap;<br />
ConType = (short) on_type;<br />
if(on_type != TwOn.DontCare)<br />
{<br />
Handle = Twain.GlobalAlloc( 0x42, 6 );<br />
IntPtr pv = Twain.GlobalLock( Handle );<br />
Marshal.WriteInt16( pv, 0, (short) type);<br />
Marshal.WriteInt32( pv, 2, (int) val );<br />
Twain.GlobalUnlock( Handle );<br />
}<br />
}<br />
<br />
public TwArray GetTwArray()<br />
{ <br />
TwArray arr = (TwArray)Marshal.PtrToStructure(Twain.GlobalLock(Handle), typeof(TwArray));<br />
ushort[] result = arr.GetUInt16Array();<br />
Twain.GlobalFree(Handle);<br />
return arr;<br />
}
3. Implemented the code as follows in the Acquire() method.
TwCapability capAll = new TwCapability(TwCap.SupportedCaps, TwOn.Array, TwType.Int16, -1);<br />
rc = DScap( applicationIdentity, sourceIdentity, TwDG.Control, TwDAT.Capability, TwMSG.Get, capAll);<br />
TwArray arr = capAll.GetTwArray();
Now, when I put a breakpoint in the GetTwArray class and try to view the result array, I get the following. I know the array is the correct length as I've validated it against Twains twack utility, however the values are not as I would expect. There may be a tell tale sign in the fact that the values repeat themselves every 8 occurances, but I don't know what to make of that. Has anyone been able to implement this successfully, or can anyone suggest where I'm going wrong?
{Length=29}
[0]: 1
[1]: 0
[2]: 0
[3]: 20092
[4]: 154
[5]: 29
[6]: 0
[7]: 1
[8]: 0
[9]: 0
[10]: 20092
[11]: 154
[12]: 29
[13]: 0
[14]: 1
[15]: 0
[16]: 0
[17]: 20092
[18]: 154
[19]: 29
[20]: 0
[21]: 1
[22]: 0
[23]: 0
[24]: 20092
[25]: 154
[26]: 29
[27]: 0
[28]: 1
many thanks, in advance
|
|
|
|
|
I'm working on this as well.
My results are:
[0] 1 ushort
[1] 0 ushort
[2] 0 ushort
[3] 51148 ushort
[4] 818 ushort
[5] 23 ushort
[6] 0 ushort
[7] 1 ushort
[8] 0 ushort
[9] 0 ushort
[10] 51148 ushort
[11] 818 ushort
[12] 23 ushort
[13] 0 ushort
[14] 1 ushort
[15] 0 ushort
[16] 0 ushort
[17] 51148 ushort
[18] 818 ushort
[19] 23 ushort
[20] 0 ushort
[21] 1 ushort
[22] 0 ushort
I can't see anything wrong offhand about the approach, but I'll mess around with it some more.
|
|
|
|
|
Okay, I just got it working by doing all the pointer math by hand. Ugly, but hey.
public ushort[] GetTwArray()<br />
{<br />
IntPtr pv = Twain.GlobalLock( Handle );<br />
ushort[] result=null;<br />
unsafe<br />
{<br />
ushort* sp=(ushort*)pv.ToPointer();<br />
uint* ip;<br />
ushort ItemType;<br />
uint NumItems;<br />
ItemType=*sp;<br />
sp++;<br />
ip=(uint*)sp;<br />
NumItems=*ip;<br />
ip++;<br />
sp=(ushort*)ip;<br />
result=new ushort[NumItems];<br />
for (int i=0;i<result.Length;i++)<br />
{<br />
result[i]=*sp;<br />
sp++;<br />
}<br />
}<br />
Twain.GlobalUnlock(Handle);<br />
return result;<br />
}
|
|
|
|
|
Very nice, but i think after all you must free unmanaged memory
|
|
|
|
|
Hello:
I'd like to get a VB.net version of this application. I can't translate it to VB.net...it's very difficult for me, and I have to finish my application, using this application. Please please please...
AMAIA
|
|
|
|
|
Hello AMAIA. we do have same scenario. i am also looking for VB.Net version on this code but i couldnt find any. I really need this features on my new application.
Thanks and wishing that somebody will share thier VB.Net version on this features.
wilson
|
|
|
|
|
to have a VB.net version
you can convert the original project to #Develop
and then convert it to vb.net
I don't know if it's work
Kore
|
|
|
|
|
You can find a translated to VB.Net version of this code here:
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=1551&lngWId=10
Olivier DALET
|
|
|
|
|
|
Hi guys
I´m working whit a flat scanner, i wanna set up the resolution more than 1200 dpi but the program don´t response this order, i don´t know why.
The Units are set up good, the program run perfect with 1200 dpi, but the program don´t run with more than 1200 dpi.
I´m trying to set up a range, but the program don´t response. The code is the folowing
Code TwainLib.cs
TwRange neuRangeXAufl = new TwRange();
neuRangeXAufl.MinValue = 100;
neuRangeXAufl.MaxValue = 1200;
neuRangeXAufl.StepSize = 100;
neuRangeXAufl.CurrentValue = 1200;
TwCapabilityR capXAufl = new TwCapabilityR( TwCap.IXResolution, neuRangeXAufl );
rc = DScapRange( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, neuRangeXAufl );
if( rc != TwRC.Success )
{
CloseSrc();
return;
}
[DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DScapRange( [In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, TwRange SetTwRange );
TwainDefs.cs
/* TWON_ARRAY. Container for array of values (a simplified TW_ENUMERATION) */
[StructLayout(LayoutKind.Sequential, Pack=2)]
internal class TwArray
{
public short ItemType;
public int NumItems; /* How many items in ItemList */
[MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
public short[] ItemList; /* Array of ItemType values starts here */
}
/* TWON_ENUMERATION. Container for a collection of values. */
[StructLayout(LayoutKind.Sequential, Pack=2)]
internal class TwEnumeration
{
public short ItemType;
public int NumItems; /* How many items in ItemList */
public int CurrentIndex; /* Current value is in ItemList[CurrentIndex] */
public int DefaultIndex; /* Powerup value is in ItemList[DefaultIndex] */
[MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
public short[] ItemList; /* Array of ItemType values starts here */
}
/* TWON_ONEVALUE. Container for one value. */
[StructLayout(LayoutKind.Sequential, Pack=2)]
internal class TwOneValue
{
public short ItemType;
public int Item;
}
/* TWON_RANGE. Container for a range of values. */
[StructLayout(LayoutKind.Sequential, Pack=2)]
internal class TwRange
{
public short ItemType;
public short MinValue; /* Starting value in the range. */
public short MaxValue; /* Final value in the range. */
public short StepSize; /* Increment from MinValue to MaxValue. */
public short DefaultValue; /* Power-up value. */
public short CurrentValue; /* The value that is currently in effect. */
}
[StructLayout(LayoutKind.Sequential, Pack=2)]
internal class TwCapabilityR
{ // TW_CAPABILITY_RANGE
public TwCapabilityR( TwCap capR )
{
Cap = (short) capR;
short i = 6;
short[] ConType = new short[i];
}
public TwCapabilityR( TwCap capR, TwRange rangeVek )
{
Cap = (short) capR;
short i = (short) TwOn.Range;
short[] ConType = new short[i];
Handle = Twain.GlobalAlloc( 0x42, 6 );
IntPtr pv = Twain.GlobalLock( Handle );
Marshal.PtrToStructure(pv, rangeVek );
Twain.GlobalUnlock( Handle );
}
~TwCapabilityR()
{
if( Handle != IntPtr.Zero )
Twain.GlobalFree( Handle );
}
public short Cap; // id of capability to set or get, e.g. CAP_BRIGHTNESS
public TwRange ConType; // TWON_RANGE
public IntPtr Handle; // Handle to container of type Dat
}
If anyone have the solution, please can you help me!
kind Regards
Marcelo
|
|
|
|
|
Hello:
I'm completly lost in this theme , and I'd like you to tell me how can I scan a document from my VB.net application, and save separatly the different words that appear in that document (an OCR). You can write me the solution as well to: amaia.ruiz@gmail.com I need it urgent....Thanks in advance.
|
|
|
|
|
HI!
I'm trying to load multiple images from my scanners tray.
But, changing the following line did NOT help:
TwCapability cap = new TwCapability( TwCap.XferCount, 1 );
to...
TwCapability cap = new TwCapability( TwCap.XferCount, -1 );
The other option I thought of, is setting the ShowUI to 0:
guif.ShowUI = 0; //Changed
and then do a scan in a while(true) with a breakpoint when the tray is empty. (I hoped that an exception or something would then be thrown)
This did not work either! Because when I disabled the UI, the tray-emptiness-detection went down the drain too, so the scan is started even when the tray is empty..
Does anyone know what to do? I'm really stuck here, and have spent many hours on this..
Help is really appreciated.
|
|
|
|
|
same problem goes here?
please help netmaster...
Jwalant Soneji (BE IT)
Mobile: +91 9969059127
http://jnsoneji.spaces.live.com
http://jnsoneji.blogspot.com
|
|
|
|
|
hello im a student of industrial ingeniering im elavorate my final proyect and i need help for capture images and save it. i see this example and I need to know like you can change the form to copy the images to be able to copy them directly all in a directory, and also like they could fade the imagens captured previously in the window of capturing images.
Thank you.
Isaac
|
|
|
|
|
Hello,
Everytime I try to change resolution, the answer from twain is 'Check_Status'... I was wondering if it's only my issue or you have sth similiar? Actually, I didn't manage to change ICAP_UNITS to Pixels because I always receive 'Failure' after such try... Here's the code I'm using:
TwCapability capUnit = new TwCapability( TwCap.IUnits, 5 );
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capUnit );
TwCapability capResx = new TwCapability( TwCap.IXResolution, 300);
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResx );
TwCapability capResy = new TwCapability( TwCap.IXResolution, 300);
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResy );
and of course everything is defined like it should:
internal enum TwCap : short
{
XferCount = 0x0001,
ICompression = 0x0100,
IPixelType = 0x0101,
IUnits = 0x0102,
IXferMech = 0x0103,
IXResolution = 0x1118,
IYResolution = 0x1119
}
|
|
|
|
|
TwCapability capResx = new TwCapability( TwCap.IXResolution, 300);
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResx );
TwCapability capResy = new TwCapability( TwCap.IYResolution, 300);
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResy );
internal enum TwCap : short
{
IXResolution = 0x1118,
IYResolution = 0x1119
}
That's OK.
Could you tell me that how to get the Grayscale's value(0x????).
thanks.
|
|
|
|
|
I know about this one ... unfortunatelly it doesn't and will not work on all scanners (DS returns CheckStatus after such try and doesn't change values - like in my case). I found where the problem lies and wanted to share my idea with codeproject users:
ICAP_RESOLUTIONX (0x1118) and ICAP_RESOLUTIONY (0x1119) doesn't accept INT16 values, that's why I propose such changes:
"TwainDefs.cs"
<br />
...<br />
internal class TwCapability<br />
...<br />
public TwCapability( TwCap cap, short sval, TwType twtype )<br />
...<br />
Marshal.WriteInt16( pv, 0, (short) twtype );<br />
...<br />
And you should use it in this way:
<br />
TwCapability capResX = new TwCapability(TwCap.IXResolution, resX, TwType.Fix32);<br />
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResX);<br />
To change between black/white / grayscale / color you should use ICAP_PIXELTYPE (0x0101) and you use this way:
<br />
TwCapability capPixelType = new TwCapability(TwCap.IPixelType, pixelType, TwType.Int16);<br />
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capPixelType);<br />
Greetings - TroLoo
|
|
|
|
|
TroLoo was right on the money about the resolution caps not accepting INT16. So I expiremented with creating a new class and trying it out.
[StructLayout(LayoutKind.Sequential, Pack=2)]<br />
internal class TwCapability32<br />
{
public TwCapability32( TwCap cap )<br />
{<br />
Cap = (short) cap;<br />
ConType = -1;<br />
}<br />
public TwCapability32( TwCap cap, short sval )<br />
{<br />
Cap = (short) cap;<br />
ConType = (short) TwOn.One;<br />
Handle = Twain.GlobalAlloc( 0x42, 6 );<br />
IntPtr pv = Twain.GlobalLock( Handle );<br />
Marshal.WriteInt16( pv, 0, (short) TwType.Fix32 );<br />
Marshal.WriteInt32( pv, 2, (int) sval );<br />
Twain.GlobalUnlock( Handle );<br />
}<br />
~TwCapability32()<br />
{<br />
if( Handle != IntPtr.Zero )<br />
Twain.GlobalFree( Handle );<br />
}<br />
public short Cap;<br />
public short ConType;<br />
public IntPtr Handle;<br />
}<br />
Now add a DLL Call
[DllImport("twain_32.dll", EntryPoint="#1")]<br />
private static extern TwRC DScap( [In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwCapability32 capb );<br />
Then Set up your resolutions like so...
<br />
TwCapability32 capX = new TwCapability32( TwCap.ICAP_XRESOLUTION , 100 );<br />
<br />
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability , TwMSG.Set, capX );<br />
if( rc != TwRC.Success )<br />
{<br />
CloseSrc();<br />
return;<br />
}<br />
<br />
TwCapability32 capY = new TwCapability32( TwCap.ICAP_YRESOLUTION , 100 );<br />
<br />
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability , TwMSG.Set, capY );<br />
if( rc != TwRC.Success )<br />
{<br />
CloseSrc();<br />
return;<br />
}
That should give you 200dpi (X*100 and Y*100)
I added this part in the Twain.Aquire() right before you set the TwCap.XferCount.
Hope it works for the rest of you.
Echooff3
|
|
|
|
|
hi can you please tell me how to scan in grayscale.. im trying but not success..
i have to deliver the project this friday but still i cannot scan it using grayscale. plssss replyyyyy!!!!
tkx in adavance!
Ludmal De Silva
.Net Developer
|
|
|
|
|
|
I'm still not getting it to work.
internal enum TwCap : short<br />
{<br />
XferCount = 0x0001,
ICompression = 0x0100,
IPixelType = 0x0101,<br />
IUnits = 0x0102,<br />
IXferMech = 0x0103,<br />
BITDEPTH = 0x112b,<br />
ICAP_IMAGEFILEFORMAT = 0x110c,<br />
ICAP_XRESOLUTION =0x1118,<br />
ICAP_YRESOLUTION =0x1119,<br />
ICAP_XNATIVERESOLUTION =0x1116,<br />
ICAP_YNATIVERESOLUTION =0x1117<br />
<br />
}
TwCapability capXRes = new TwCapability( TwCap.ICAP_XRESOLUTION , 300);<br />
rc = DScap( appid, srcds, TwDG.Control , TwDAT.Capability , TwMSG.Set , capXRes );<br />
if( rc != TwRC.Success )<br />
{<br />
CloseSrc();<br />
getStaus();<br />
return;<br />
}<br />
GetStatus it telling me the condition code is 11 TWCC_SEQERROR : DG DAT MSG out of expected sequence
public void getStaus(){<br />
TwRC rc = new TwRC();<br />
TwStatus tws = new TwStatus() ;<br />
rc = DSstatus(appid,srcds,TwDG.Control,TwDAT.Status,TwMSG.Get,tws);<br />
System.Windows.Forms.MessageBox.Show(tws.ConditionCode.ToString());<br />
return;<br />
}
Any Ideas???
|
|
|
|
|
Hi,
Finally managed to get the resolution changed on the Scanner, very simple really once you know what's happening. The clue is Resolutions that I'm using are DPI, so
First line should read
TwCapability capUnit = new TwCapability( TwCap.IUnits, 0 );
Set the units to inches, the rest follows.
|
|
|
|
|
Please can you explain what I must do to change the resoltution of scanning?
Thanks you very much,
Mosquets
|
|
|
|
|