|
Ok I found the re-written version of this project in vb.net and so the syntax is different, but same concept. I've added the TW_EXTIMAGEINFO struct and TW_INFO struct to the project. Also added the TWEI enum and another dll function called 'DSeiinf(...)'.
Here is the code:
just the declaration in TwainLib.vb:
<br />
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSeiinf(<[In](), Out()> ByVal origin As TwIdentity, <[In]()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, <[In](), Out()> ByVal extimginf As TW_EXTIMAGEINFO) As TwRC<br />
End Function<br />
Here is the code added in the TwainDefs.vb that I added:
just declaring the TWEI constants (only one i'm interested in)
Friend Enum TwEi As Short
TWEI_BARCODETEXT = &H1202
End Enum
definitions of the two structs needed for the DC_IMAGE/DAT_EXTIMAGEINFO/MSG_GET combo
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TW_EXTIMAGEINFO
Public NumInfos As Integer = 1
Public Info(0) As TW_INFO
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TW_INFO
Public InfoID As Short
Public ItemType As Short
Public NumItems As Short
Public ReturnCode As Short
Public Item As IntPtr
End Class
Code added in a sub to get the data after scanning has been done in TwainLib.vb.
Public Sub getPictureInfo()
Dim extimginf As New TW_EXTIMAGEINFO
Dim inf1 As New TW_INFO
Try
inf1.InfoID = CType(TwEi.TWEI_BARCODETEXT, Short)
inf1.ItemType = 0
inf1.NumItems = 0
inf1.ReturnCode = 0
inf1.Item = 0
extimginf.Info(0) = inf1
Dim rc As TwRC = DSeiinf(appid, srcds, TwDG.Image, TwDAT.ExtImageInfo, TwMSG.Get, extimginf)
If (rc <> TwRC.Success) Then
'CloseSrc()
Return
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
This sub is called on a menuItem_click event and I've been calling it after the image(s) are scanned. But rc is always 'failure'. I've read about you can only get the extimageinfo at state 7 of the scan process, but I have no clue how to do that. Any help would be awesome.
Thanks,
Justin
|
|
|
|
|
I found this: http://nt.twain.org/docs/TWTestRecAddendum.PDF[^]
If you do a ctrl + f for DAT_EXTIMAGEINFO it seems there is a test that seems to work everytime that they supply, but does each DS..() call count as a certain "state"?
If not I'm truly lost lol.
Thanks again,
Justin
|
|
|
|
|
Our program need to disable the default UI. so we do the following code.
set the capability,
TwCapability capBrightness = new TwCapability(TwCap.ICAP_BRIGHTNESS, 100, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capBrightness);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
get the capability.
TwCapability capbright = new TwCapability(TwCap.ICAP_BRIGHTNESS, TwOn.Range, TwType.Fix32, -1);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Get, capbright);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
else
{
TwRANGE arr = capbright.GetTwRange();
//TwRANGE arr = (TwRANGE)Marshal.PtrToStructure(Twain.GlobalLock(Handle), typeof(TwRANGE));
}
internal class TwRANGE{
ushort ItemType;
uint MinValue; /* Starting value in the range. */
uint MaxValue; /* Final value in the range. */
uint StepSize; /* Increment from MinValue to MaxValue. */
uint DefaultValue; /* Power-up value. */
uint CurrentValue; /* The value that is currently in effect. */
}
But I find that its MaxValue 1000, MinValue 64536; Current Value 65636.
So what is the problem? I could set brightness in the Default UI, but why i can't set in our Customized Acquire?????
|
|
|
|
|
internal class TwRANGE{
ushort ItemType;
TwFix32 MinValue; /* Starting value in the range. */
TwFix32 MaxValue; /* Final value in the range. */
int StepSize; /* Increment from MinValue to MaxValue. */
TwFix32 DefaultValue; /* Power-up value. */
TwFix32 CurrentValue; /* The value that is currently in effect. */
}
Now I using this, so the capa which i was setting now is showing correct.
MaxValue 1000,
MinValue -1000;
Current Value -800.
itemType 7
stepSize 1
defaultValue 0
but the problem is that the image scanned stay no change at all.
|
|
|
|
|
Now I use the Twack_32.exe program.
it could set up the DPI, but not the brightness.(through the capability setting, state workflow in special menu)
so i really really curious about how the default UI did this to set the brightness. waiting for the replies.....
Is that any twain version issue?
since the twain_32.dll already in the C:\WINDOWS, created in Wednesday, August 04, 2004, I removed it, but when I run our program, it will automatically generated again.(I wonder why)
and the BenQ disc folder twain_32.dll created in Tuesday, October 22, 1996.
|
|
|
|
|
TWAIN, twain_32.dll, TWAIN version - have nothing to do with this, the commands you are using are all passed directly to the scanner's TWAIN driver - so it's entirely a driver issue.
We've seen some TWAIN drivers that just ignore the value of ICAP_BRIGHTNESS (and/or ICAP_CONTRAST), even though the driver 'supports' these capabilities.
One thing to try: Make sure the value of ICAP_AUTOBRIGHT is FALSE, assuming your scanner supports ICAP_AUTOBRIGHT, before trying to set ICAP_BRIGHTNESS.
When you say "default UI" - what are you talking about exactly? The scanner UI on Windows (and Mac) is provided by each driver, there is no default UI in TWAIN. So, the BenQ UI can do anything! Because it is not using the TWAIN interface to control the driver, it is inside/part of the driver.
Oh - I think the reason twain_32.dll comes back is because it is a protected Windows system DLL - Windows restores it if it is damaged or deleted.
Hope this helps in some way...
spike _/\_ (Spike0xFF)
|
|
|
|
|
i am faceing one problem. if i use the UI dialogue brought up by the DS, I can modify the brightness/contast.
but when i disable the UI, i can set the capability successfully, but it is just not worked on the image.
here is the following my program.
// Set the X resolution
TwCapability capResX = new TwCapability(TwCap.CAP_RESX, 50, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResX);
if (rc != TwRC.Success) { CloseSrc(); return; }
// Set the Y resolution
TwCapability capResY = new TwCapability(TwCap.CAP_RESY, 50, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResY);
if (rc != TwRC.Success) { CloseSrc(); return; }
// Set the scan type // 0 = BW | 1 = Gray | 2 = Colour
TwCapability capPixelType = new TwCapability(TwCap.IPixelType, 2);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capPixelType);
if (rc != TwRC.Success) { CloseSrc(); return; }
//// Set the brightness (doesn't work for BW)
TwCapability capBrightness = new TwCapability(TwCap.ICAP_BRIGHTNESS, -510, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capBrightness);
if (rc != TwRC.Success) //here return success
{
CloseSrc();
return;
}
|
|
|
|
|
How i can Acquire all the images in picture box.
modified on Monday, January 18, 2010 6:46 AM
|
|
|
|
|
Hi,
This question was asked by someone else back in 2006, but never answered. I need an answer now, so any help would be appreciated!
I want to list available scanners in my own listbox, not in twain's gui. Becuse i want to use alias names of scanners and give users a seperare was to select the scanner they want. Basically, I want the control directly in my own application and not via the Twain GUI.
Also, the Twain GUI gives a list of scanners whose drivers were installed. It does NOT actaully give a list of scanners that are actually connected (and available) to the computer. Obvioiusly I would like my list to just display scanners that are connected to the computer at that moment in time.
I am currently developing using Visual Basic vis VN.Net 2008 However is someone has the code in C I can convert it.
Thanks in advance for any help. - DLT
|
|
|
|
|
To get a list you would need to use the TWAIN methods of querying the interface. For example:
public ArrayList GetScanners()
{
ArrayList al = new ArrayList();
TwRC rc = DSMident( appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetFirst, srcds );
while ( rc != twainDefs.TwRC.EndOfList )
{
al.Add( srcds.ProductName );
rc = DSMident( appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetNext, srcds );
}
return al;
}
As for verifying that the scanners are plugged in at that moment, I don't know. I recently worked with a commercial control and they had no way of doing this either. It would wind up being more efficient to just test that scanner once it's selected.
|
|
|
|
|
hello,
I have done something for the same issue .i have successfully feel deropdownbox with devices but i m getting problem while i m selecting source device from my own dropdownbox please tell me what kind of changes i have to do so that it can work properly..here is my code snippet
..please help me..
these are some methods that i have used and added in Twainlib.cs
---------------------------------------------
public bool SelectSource(int SourceIndex)
{
ArrayList _Sources = new ArrayList();
_Sources=GetDataSources();
srcds = (TwIdentity)_Sources[SourceIndex];
TwRC rc;
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.Set, srcds);
if (rc != TwRC.Success)
return false;
return true;
}
public ArrayList GetDataSources()
{
ArrayList ds = new ArrayList();
ArrayList _Sources = new ArrayList();
TwIdentity scanner = new TwIdentity();
TwIdentity defScanner = new TwIdentity();
CloseSrc();
if (DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetFirst, scanner) == TwRC.Success)
{
_Sources.Add(scanner.ProductName);
scanner = new TwIdentity();
}
while (DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetNext, scanner) == TwRC.Success)
{
_Sources.Add(scanner.ProductName);
}
return _Sources;
}
-------------------------
And in mainform.cs
------------------------
//For filling up dropdownbox
devices = tw.GetDataSources();
cmbSelectSrc.DropDownStyle = ComboBoxStyle.DropDownList;
cmbSelectSrc.DataSource = devices;
//And by selecting this method is called
----------
private void cmbSelectSrc_SelectedIndexChanged(object sender, EventArgs e)
{
tw.SelectSource(cmbSelectSrc.SelectedIndex);
}
while i m selecting device it gives
Unable to cast object of type 'System.String' to type 'TwainLib.TwIdentity'
|
|
|
|
|
can someone tell me how to change the resolution and i also want to capture image as black and white. can someone help me? any help would be welcome.(I want to hide the UI and give the parameters from the code only)
|
|
|
|
|
// Set the X resolution
TwCapability capResX = new TwCapability(TwCap.CAP_RESX, 50, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResX);
if (rc != TwRC.Success) { CloseSrc(); return; }
// Set the Y resolution
TwCapability capResY = new TwCapability(TwCap.CAP_RESY, 50, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResY);
if (rc != TwRC.Success) { CloseSrc(); return; }
// Set the scan type // 0 = BW | 1 = Gray | 2 = Colour
TwCapability capPixelType = new TwCapability(TwCap.IPixelType, 2);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capPixelType);
if (rc != TwRC.Success) { CloseSrc(); return; }
|
|
|
|
|
|
Is there a way to get the image without the HP screen which i get when i click on acqiure
Any help would be welcome
|
|
|
|
|
In TwainLib.cs search for function Acquire().
There you will find:
TwUserInterface guif = new TwUserInterface();
guif.ShowUI = 1;
guif.ModalUI = 1;
Make this:
TwUserInterface guif = new TwUserInterface();
guif.ShowUI = 0;
guif.ModalUI = 0;
I hope that this is what you mean...
|
|
|
|
|
Thanks. That is exactly what i wanted. thank you once again.
|
|
|
|
|
First Thanks for the code. After a long day +1 of attempting to get the duplex mode running using the instructions in the below message thread
" Use Duplex with Driver Twain - Help URGENT " I finally got the duplex mode by incorporating the code from that message thread along with setting from 1 to 2 in TwainLib.cs (line 102 +-)
TwCapability cap= newTwCapability( TwCap.XferCount, 2 );
Hope this helps someone!
Morke
|
|
|
|
|
Hi, I find the application very useful, 10x to the authors. But I want to do a slightly different thing - when I choose 'acquire' to capture a picture of what is in the scanner automatically (I don't want to see the default software of the TWAIN interface, to capture a picture etc...) Simply - with a single click in my application to get a scanned picture. Is it possible? Or is there any documentation of twain_32.dll ?
|
|
|
|
|
hello,
I have Downloaded code and use same code by .NETMASTER
and is running nicely on my pc but when i port this project to other machine its not running it gives error dialog box(error-cheack originals,No originals in feeder),its allows us to select source but on acquire it gives this error, even i have installed driver for scanner .so my question is ,is there any dependency of "twain_32.dll"?
in code i didn't find any dependency .(references about twain.dll).so help me what i have to do ?As i have little knowledge of twain please help me(by email)
please ...
|
|
|
|
|
Yes TWAIN started out as a 16-bit API.
That would be on the famous 16-bit operating system (Windows) where it was used for scanning by that famous 16-bit image editor, Adobe Photoshop.
Pretty hard to find anybody who cares about those origins today, except students of technology history, and chest-pounding Apple fanboys.
I've been doing 32-bit TWAIN programming since 1996, and TWAIN has evolved far more, and is far more suitable for production/commercial scanning, than WIA.
WIA is great for digital cameras - it's the best vendor-independent digital camera API.
And it's simpler to code to than TWAIN (if your language is COM-aware), so it makes sense for small one-off projects to do simple scanning in VB or .NET, where just coming up to speed is a big part of the project effort, and you can't justify buying a commercial scanning library or component.
I think you'll find that in serious scanning software, TWAIN is almost universally supported, ISIS is fairly widely supported especially for 'high-end' applications, and WIA is explicitly supported only by a few consumer/small-office packages. Since all WIA scanners also appear as TWAIN devices thanks to a Microsoft-provided TWAIN-to-WIA bridge, the only reason for coding directly to WIA (once you support TWAIN) is to support those few scanners that don't have a native TWAIN driver AND that trigger certain long-standing bugs in the Microsoft TWAIN-to-WIA bridge.
spike _/\_ (Spike0xFF)
|
|
|
|
|
im newbies in C#.net , please help me on coding that i can save image into .pdf file .
thanks
ringku2k
|
|
|
|
|
Load you scanned image into ImagXpress and follow the below code. It should be fine.
Dim so As SaveOptions = New SaveOptions()
so.Format = ImageXFormat.Pdf
Dim pro As Processor = New Processor(ImagXpress)
pro.Image = ImageXView1.Image
pro.Crop(cropRect)
ImageXView1.Image.Save("C:\updated.pdf", so)
|
|
|
|
|
I was wondering if it would be possible to post an update with the changes you have made since the orignal post. Especially I would be interested on how to best implement the retrival of the CAP_FEEDERENABLED, CAP_FEEDERLOADED capabilities.
I can not seem to figure out how to do this.
thanks in advance
Mike
|
|
|
|
|
|