|
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
|
|
|
|
|
Hey NetMaster,
Nice code, but how come the application only scans one page at a time?
How come when you scan in a number of pages (i set cap = -1 to get ADF running) that the scanner produces individual images? how would i go about specifying that i wanted one multipage document instead of 6 individual pages?
Is this a built-in feature to the code?
do i need to modify the original code?
Has anyone else noticed this?
Regards,
Max
Dublin
Ireland
|
|
|
|
|
MaxJam wrote:
Is this a built-in feature to the code?
No, instead of saving individual images you have to create multiframe TIFF file. This article should help you start:
http://www.codeproject.com/csharp/TiffManager.asp
MaxJam wrote:
do i need to modify the original code?
Original code of what? You mean this sample application? Of course...
|
|
|
|
|
i am working on a document management system..
which will be developed using VB.NET and ASP.NET.
THe VB application will first scan the documents and add the details on the sam epage the images should be stored as the document code name .gif/jpg and also th eimages shoul dbe optimised..
can anyone help me with
1) finding an dll which i can use to scan it thorugh my application.
2) image optimiser dll which would act on it and optimise it as per the requirement.
an immidiate response would be a life saver..
Mansoor Baig
Cyber Link
Saudi Arabia
mansoor@mansoorbaig.com
|
|
|
|
|
First of all lemme thank the developer. You're awesome dude!
Now, Herez my question. How do I scan multiple pages using the code? I would like to specify if I am scanning one page, or more, or specific number of pages, is this possible ?
If at first you don't succeed, then skydiving isn't for you.
|
|
|
|
|
Respected Sir,
I want to change DPI of scanning device. Default DPI is 1200 which results too much processing overhead.
How can I change DPI of a scanner.
using TWAIN API.
Regards
Ahmad Javed
|
|
|
|
|
Following method will change the DPI settings:
---------------------------------------------
internal void ChangeImageQuality(int val)
{
try
{
// following lines will set the unit of measure as pixel.
mobjTwain.Capability = PegasusImaging.WinForms.TwainPro4.tagenumCapability.TWCAP_UNITS;
if (mobjTwain.CapSupported == true)
{
mobjTwain.CapTypeOut = PegasusImaging.WinForms.TwainPro4.tagenumCapType.TWCAP_ONEVALUE;
mobjTwain.CapValueOut = 5;
mobjTwain.SetCapOut();
}
// Change the XResolution.
mobjTwain.Capability = PegasusImaging.WinForms.TwainPro4.tagenumCapability.TWCAP_XRESOLUTION;
if (mobjTwain.CapSupported == true)
{
mobjTwain.CapTypeOut = PegasusImaging.WinForms.TwainPro4.tagenumCapType.TWCAP_ONEVALUE;
mobjTwain.CapValueOut = val;
mobjTwain.SetCapOut();
}
// Change the YResolution
mobjTwain.Capability = PegasusImaging.WinForms.TwainPro4.tagenumCapability.TWCAP_YRESOLUTION;
if (mobjTwain.CapSupported == true)
{
mobjTwain.CapTypeOut = PegasusImaging.WinForms.TwainPro4.tagenumCapType.TWCAP_ONEVALUE;
mobjTwain.CapValueOut = val;
mobjTwain.SetCapOut();
}
}
catch (Exception ex)
{
this.ThrowException(ex);
}
}
|
|
|
|
|
Hi, I will really appreciate if you can help me…
I was wondering if there is a possible way to use twain source to take snapshots (every 200miliseconds) with a webcam? Or how difficult it would be..
I saw that twain has an interface to take picture with the webcam, but I don’t know if it is configurable to take snapshots within an interval time.
Thanks so much
Regards,
|
|
|
|
|
Hello, programmers!
Can anyone show me the way, how i can get image from scaner from client machine and upload it onto server, using asp.net!
Specifically i am interested in: how to upload Image on server, how to use above mentioned code in web, which does not supports message-pools?
I will be glad to receive some example code or advice!
You can also send solutions on my email: AGorbushkin@gse.ge
Thanks in advance!
|
|
|
|
|
I would like to save the image scanned to a Stream so i can use it internally.
I have been searching and found a function called "GdipSaveImageToStream" which allows saving to a stream, but i have no idea how to make this call from c#. It uses a IStream parameter and i don’t know how i must configure the DLLImport. Can somebody please help me?
Tnx
chsfly
|
|
|
|
|
I figured out an easier way of doing this than GdipSaveImageToStream. Create a bitmap and get the Graphics dc from it.
Bitmap me = new Bitmap(bmprect.Width, bmprect.Height);
Graphics g = Graphics.FromImage(me);
IntPtr hdc = g.GetHdc();
SetDIBitsToDevice(hdc, 0, 0, bmprect.Width, bmprect.Height,
0, 0, 0, bmprect.Height, pixptr, bmpptr, 0);
g.ReleaseHdc(hdc);
The image is now in the bitmap for you to save or do whatever!;)
|
|
|
|
|
Concerning the code to create the bitmap. Where are you placing it? Should it go in the PicForm of the sample or does it need to go in the MainForm? New to this graphics stuff so I am looking for a little guidence......
Thanks, TD
|
|
|
|
|
thank you very much for above code
|
|
|
|
|
Dim oStream As IStream
CreateStreamOnHGlobal(Nothing, True, oStream)
'Dim oStream As New MemoryStream
st = GdipSaveImageToStream(img, oStream, clsid, IntPtr.Zero)
oStream.Seek(Nothing, StreamSeekType.STREAM_SEEK_END, curMax) ' get the size of the stream
oStream.Seek(Nothing, StreamSeekType.STREAM_SEEK_SET, Nothing) ' return to the beginning
Dim bBmpBits() As Byte
ReDim bBmpBits(curMax(0).QuadPart - 1)
oStream.Read(bBmpBits, curMax(0).QuadPart, lBytesRead) ' note that lBytesRead could overflow, please fix this if you're reading more than 2 Gigs :P
Dim fs As New FileStream("c:\1.tif", FileMode.Create)
Dim os As New System.IO.BinaryWriter(fs)
os.Write(bBmpBits)
|
|
|
|
|