|
I'm developing a student project which makes use a scanner.
i surf to the web over and over and download many codes about handling a scanner.
some of them use Twain, some of them use the kodak image control (i'm developing the project with vb.net)
I'm confused with the difference of TWAIN and Kodak Image Control. What's the difference?
I'm trying to use KIC to handle the scanner without the UI. But I find that I can't micro-control the scanner. Without UI, the scanner always scan as letter size but not A4 size. How can i set the region?
I sincerely hope that someone can give me a hint and, most importantly, how to control the scanning region.
Thousand thx!
|
|
|
|
|
Reply me your e-mail, and I'll give you a advanced version of TWAIN controler.
Hope that can help you.
BTW, where do u live in?
————————————————————————————————————————
Sumtec宇宙技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利,并保持和微软所提供的条款一致。具体É
|
|
|
|
|
Hi,
I'm can't set the resolution of the scanner. This is what i'm trying to use:
TwCapability cap2 = new TwCapability(TwCap.ICAP_XRESOLUTION, 0x004b);
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap2 );
if( rc != TwRC.Success )
{
CloseSrc();
return;
}
This code is in Acquire() after the line:
"rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap );"
As this line works and it's in state 4, my code should work too.
But I always receive "TwRC.Failure" and, in CloseSrc(), I get this message:
"General failure in response to MSG_DISABLEDS. DG DAT MSG is out of expected sequence."
Anybody can help-me please?
Thanks!
Edgar
|
|
|
|
|
Use this:
Resolution = 300 //Resolution in dpi.
// Define this.
ICAP_XRESOLUTION = 0x1118
ICAP_YRESOLUTION = 0x1119.
// Set X resolution.
TwCapability capX = new TwCapability(TwCap.ICAP_XRESOLUTION, Resolution);
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capX );
if( rc != TwRC.Success ) {
CloseSrc();
return;
}
// Set Y resolution.
TwCapability capY = new TwCapability(TwCap.ICAP_YRESOLUTION, Resolution);
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capY );
if( rc != TwRC.Success ) {
CloseSrc();
return;
}
Anybody know how setting X and Y dimension of rectangle of acquisition?
Thanks
|
|
|
|
|
Thank you for this so useful application...
I would like to use feeder while scanning. How can I use feeder?
|
|
|
|
|
I suggest you to read the TWAIN document. With a bit changes with these sources the author supplied, you can use the feeder while scanning. As I don't need to use feeder, I didn't make my version of twain scanning component have the ability of feeding. So, I'm very sorry to say I can not help you directly with my advanced component. However, my source contained some new structure you may have to use, such as TW_ENUMERATION/ TW_ARRAY/ TW_RANGE, etc.
As a tip, read about the content of "Capabilities" in the TWAIN document. The keywords you need are:
CAP_SUPPORTEDCAPS
CAP_FEEDERENABLE
CAP_FEEDERLOADED
CAP_AUTOFEED
CAP_CLEARPAGE
CAP_REWINDPAGE
DG_CONTROL/ DAT_CAPABILITY/ MSG_GET
DG_CONTROL/ DAT_CAPABILITY/ MSG_SET
TW_ENUMERATION
TW_RANGE
TW_ARRAY
Good luck!
————————————————————————————————————————
Sumtec宇宙技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利,并保持和微软所提供的条款一致。具体É
|
|
|
|
|
Hmm.. anyone have more information on this subject? I cannot seem to get the scanners to feed multiple pages, without running a loop checking for out of paper.. Seems to me there should be a way to do it inside of the twain specs..
|
|
|
|
|
|
Take a look at my reply to another thread:
http://www.codeproject.com/dotnet/twaindotnet.asp?msg=923006&target=netmaster#xx923006xx
A simple code change will allow multiple scans.
|
|
|
|
|
Hi,
Is there a way to hide the user interface and scan with predefined settings (resolution, region, color, ...)
Thanks.
|
|
|
|
|
Yes, u can. By reading the document "TWAIN specification", you can find that by fixing the TW_USERINTERFACE.ShowUI to false(short 0), the Source's (the device) predefined UI will not show. This can be found in the author's source code in the form of "guif.ShowUI = 1". By fixing the "1" into "0", you can hide the user interface. Some scanner prevent you from predefining settings of resolution, region, color, etc, if you show the Source's User Interface. However, when you set them, the DSM (Device Source Manager) will report the State "Success". (For example, Acer's scanners do so. In fact, it's the problem of "Mira Scan".)
If what you want is not only to hide the UI but also to set the settings, I suggest you:
1. To read TWAIN's documents which can be downloaded from HTTP://www.twain.org
The title of the document you need is "TWAIN specification version 1.9". I should notice you that the document is very long. It contains 9 chapters and 2 appendixes. And there is still a bit problems in using the TWAIN API in .NET. Maybe you will use two day to find what's wrong and to fix them.
2. Give me your mail address and I will send you my work. It can set resolution, region, color and ShowUI. And I should tell you that I didn't fixed all the problem I met, and even don't know if there is any problem I don't know yet in it. As a part of protection, I won't give all the source codes. However, I will give you the part of TWAIN's like NETMaster did here. And I bug you please, DO NOT fix any thing which completely have nothing to do with scanning, eg: product info.
————————————————————————————————————————
Sumtec宇宙技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利,并保持和微软所提供的条款一致。
|
|
|
|
|
Thanks for the c# twain sample program. It saved me at least months of time. Right now I have problem saving image to tiff file with group4 encoding or compression.
I tried to use EncoderParameters with Param[0] = new EncoderParameter( Encoder(Encoder.Compression.Guid), (byte)EncoderValue.CompressionCCITT4 ) in function GdipSaveImageToFile() as the third parameter. But I cannot make it work. Do you have any idea?
Thanks!
Yong
|
|
|
|
|
First of all, thank you for your great works.
I am doing a project with scanner and found your source here. With your help, I've made a simple class for TWAIN scanner. And the class sounds good except ... :
You can't throw any exception correctly! And I don't know if this is my problem. (I guess not.)
By fixing your code at procedure "public void Init( IntPtr hwndp )" without changing any other codes, you can see the problem:
public void Init( IntPtr hwndp )
{
Finish();
TwRC rc = DSMparent( appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp );
if( rc == TwRC.Success )
{
rc = DSMident( appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetDefault, srcds );
throw new Exception("Throw any exceptions here will finally popup StackOverflowException but not want you want.");
if( rc == TwRC.Success )
hwnd = hwndp;
else
rc = DSMparent( appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwndp );
}
}
As I trace the disassembly code, I found that the exception object can be generate correctly but after that, when throwing it, the code will unexpectly generate another exception "NullReferenceException". What's more interesting is, even the "NullReferenceException" can't be thrown -- when throwing the "Null...Exception" the code will generate a new "Null...Exception". This causes the stack overflowed and finally generate an exception "StackOverflowException".
My questions are:
1. What causes this? Especially, why you can throw an exception normally before requesting TwMessage.GetDefault?
2. How to avoid this? I mean how to make throwing exception correctly?
'Cause I want to use exceptions to tell user the problem.
And another reason, if some other unexpecting problems happen, like "Divided by zero" or "ArgumentException", which are not the programmer's willing, it will shutdown the program without showing the correct information. This make my debugging extremely difficult.
Lately I found another thing: If you put the exception-throwing-code or the problem-generating-code(I mean the codes generate exception not by my willing) into a try...catch structure, you will find that you can catch an exception instead of poping up an "Null...Exception" or an "Stack...Exception". But unfortunately, you will find that the exception you catch is not what really causes the problem. For example:
During the TransferPics stage, I convert the DIB into a Bitmap and save into disk. But if the file I want to save is occupied by another object like 'pictureBox1.Image = Image.FromFile(@"C:\temp.bmp");', the system should throw an exception to indicate that the file is occupied. Disappointing me, the system throws an exception called "General GDI+ Exception" instead of what I want.
I don't know if this information can help you to solve the problem.
I guess if there is some problem with interoperation? Because the only different between TwMessage.OpenDSM and TwMessage.GetDefault is the DSM will fill some info into the parameter/variable "srcds".
Expecting for any one's answer, especially NETMaster's.
————————————————————————————————————————
Sumtec宇宙技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利,并保持和微软所提供的条款一致。
|
|
|
|
|
Null reference.
————————————————————————————————————————
Sumtec宇宙技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利,并保持和微软所提供的条款一致。具体É
|
|
|
|
|
I seem to be running into this, or very similar, issue.
As a sample (which I accept is what the provided code is) it runs fine, and even with a slight expansion, it seems to run fine.
Bt when I start to add calls to servers and the like, it falls over, always in the same place, when I'm starting the acquire method.
The message is always that there's a null reference of an object exception, but no hint whatsoever as to where the null refeence is, or what the object might be.
Everything in the current module appears to be fine.
This looks to me like some form of memory leakage issue, and, if I slowly step through the code in the debugger, it can go away. I've tried implementing some GC calls, but with no satisfaction.
Does anybody have any clues on this?
TIA.
g.
Gary Stark
gstark@RedbacksWeb.com
http://www.RedbacksWeb.com
|
|
|
|
|
I had similar problems. I believe that the leak is related to the Acquire dialog. I modified the sample to scan into the file without opening the dialog and it always works fine. If I open the Acquire dialog, it scans OK, but after using application for a while I usually get some resource contamination and NullReferenceException thrown from a text box...
|
|
|
|
|
I am trying to port this to VB.NET, but am having trouble with the message handling. Is there a simple way to just compile this into a DLL and then use it in VB.NET?
|
|
|
|
|
Yes, all .NET languages are interoperable. You can reference the dll from your VB.NET app and then call it just like it was written in VB.NET itself.
Your bullshit is so effusive I can smell it across oceans...
You impress no-one. You are a world-class sleazeball; an incomparable jerk. No-one is fooled by your idiotic attempts to slant votes.
-A. N. Onymous on Bill SerGio
|
|
|
|
|
|
Get the latest Windows service pack and driver for your scanner.
Don't use the ones from twain.org.
|
|
|
|
|
I can not find it, can you attach it please or send it by email tarekj@hotmail.com
|
|
|
|
|
First off, great job getting TWAIN to work in .net. You saved us a bunch of time and hassle having to learn how to acquire images. Double thanks for giving the code away for free.
I have run into a problem using this technique (in addition to the pointer to Image conversion problem). If you try to acquire using a USB camera and the camera is not present the calling application gets no notification that the acquire failed - it will sit indefinitely waiting for the acquire to complete.
Using a USB Creative PC-CAM I found that even though the twain dll popped up a message box that the camera wasn't attached it didn't return a failure code or send any twain messages into the message loop. Is there any way around this?
I'm considering setting a timer and if I don't get a twain message within a certain timeout I will just cancel the acquire.
Steve
|
|
|
|
|
I guess this is not a .NET Interop issue.
Thus read the TWAIN 1.9 specification, may be
- CAP_DEVICEONLINE (9-369)
- CAP_DEVICEEVENT (9-367)
- Appendix A, Device Events
|
|
|
|
|
Is it possible to, using the classes in that article, to the scanning in a asp.NET web page ?
CU
LaMagra
|
|
|
|
|
TWAIN was not designed for this.
As far as I know there is no windows-message-loop in ASP.NET,
and TWAIN needs one.
|
|
|
|
|