|
can you help me to send picture to picturebox
please email me
e-3bdo@hotmail.com
|
|
|
|
|
may you please send me this code at
ch.ishwer@gmai.com
thanks in advance.
|
|
|
|
|
may you please send me this code at
ch.ishwer@gmai.com
thanks in advance.
|
|
|
|
|
marcos.carrera@hotmail.com
|
|
|
|
|
Hello !I am sorry to bother you!
I have read your article“Using TWAIN API to Scan Images”,I learned a lot 。But when i rewrote the code following your sample ,i found a problem 。The problem is:How can i return to multiple images when i using TWAIN API to scan images ?So can you help me ? Thanks in advance for any help.
The following is my Email address:visatest@163.com .Thank you !
|
|
|
|
|
VB.net
In twain class, Acquire method, change this line from 1 to 0 or -1
Public Sub Acquire()
CloseSrc()
If Me._appid.Id.Equals(IntPtr.Zero) Then
Init(Me._hwnd)
If Me._appid.Id.Equals(IntPtr.Zero) Then Exit Sub
End If
....
'Change the line below
Dim cap As TwCapability = New TwCapability(TwCap.XferCount, -1)
rc = DScap(Me._appid, Me._srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap)
If (rc <> TwRC.Success) Then
CloseSrc()
Exit Sub
End If
Dim guif As TwUserInterface = New TwUserInterface()
....
End Sub
C#
public void Acquire()
{
CloseSrc();
if (this._appid.Id == IntPtr.Zero)
{
Init(this._hwnd);
if (this._appid.Id == IntPtr.Zero) { return; }
}
....
// Change this line below
TwCapability cap = new TwCapability(TwCap.XferCount, -1);
rc = DScap(this._appid, this._srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwUserInterface guif = new TwUserInterface();
guif.ShowUI = Convert.ToInt16(this._showUI);
.....
}
Heavy givers are light complainers
|
|
|
|
|
Hi Folks,
Thanks a lot for this great article and FAQ.
I am facing issues when trying to perform transfert in Buffered Memory Mode in a .net application. The scanner is always responding with Failure and Condition code 10 (means “Data parameter out of range”) when I perform the DSM_Entry DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET.
Does anyone can help me ?
Here is the code for creating / allocating mem and performing the transfert:
public void Acquire()
{
…
// Config.transfertMode = 2
TwCapability capXfer = new TwCapability(TwCap.IXferMech,Config.transfertMode);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capXfer);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
…
}
public void TransferPicturesMem()
{
try
{
if (srcds.Id == IntPtr.Zero)
{
return;
}
TwRC rc;
IntPtr theImg = IntPtr.Zero;
TwPendingXfers pxfr = new TwPendingXfers();
do
{
pxfr.Count = 0;
TwSetupMemXfer smxf = new TwSetupMemXfer();
rc = DSsmxf(appid, srcds, TwDG.Control, TwDAT.SetupMemXfer, TwMSG.Get, smxf);
if (rc != TwRC.Success)
{
CloseSrc();
//TODO
return;
}
TwImageInfo iinf = new TwImageInfo();
rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf);
if (rc != TwRC.Success)
{
TwStatus status = new TwStatus();
rc = DSMstatus(appid, srcds, TwDG.Control, TwDAT.Status, TwMSG.Get, status);
CloseSrc();
//TODO Logger les echecs
return;
}
TwImageMemXfer imxf = new TwImageMemXfer(smxf.Preferred);
rc = DSixmf(appid, srcds, TwDG.Image, TwDAT.ImageMemXfer, TwMSG.Get, imxf);
// Always responding failure
if (rc != TwRC.XferDone)
{
TwStatus status = new TwStatus();
rc = DSMstatus(appid, srcds, TwDG.Control, TwDAT.Status, TwMSG.Get, status);
// Status handle condition code 10
CloseSrc();
//TODO
return;
}
rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr);
if (rc != TwRC.Success)
{
CloseSrc();
//TODO
return;
}
TwImageMemXfer img = (TwImageMemXfer)Marshal.PtrToStructure(theImg, typeof(TwImageMemXfer));
}
while (pxfr.Count != 0);
rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr);
return;
}
catch (Exception e)
{
//TODO
}
}
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwImageMemXfer
{
public TwImageMemXfer()
{
Memory = new TwMemory();
}
public TwImageMemXfer(int howMuch)
{
Compression = 0xffff;
BytesPerRow = 0xffffffff;
Columns = 0xffffffff;
Rows = 0xffffffff;
XOffset = 0xffffffff;
YOffset = 0xffffffff;
BytesWritten = 0xffffffff;
Memory = new TwMemory();
Memory.Flags = 0x10 | 0x1;
byte[] buf = new byte[howMuch];
GCHandle handle = GCHandle.Alloc(buf);
Memory.TheMem = GCHandle.ToIntPtr(handle);
Memory.Length = howMuch;
}
~TwImageMemXfer()
{
// TODO Free memory
}
public int Compression;
public uint BytesPerRow;
public uint Columns;
public uint Rows;
public uint XOffset;
public uint YOffset;
public uint BytesWritten;
public TwMemory Memory;
}
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwMemory
{
public int Flags;
public int Length;
public IntPtr TheMem = IntPtr.Zero;
}
|
|
|
|
|
matheo, I'm stuck on same issue, vb.net code but same failure condition code.
have you got any updates on that?
thank you.
|
|
|
|
|
Hi, I have the following setup.
I have a 64bit OS.
I have have a wireless camera attached on top of a robot which transmits the video to a receiver which in turn out puts the information in composite. I use a TV card to convert that to a signal more meaningful to a computer. I want to take infrequent snapshots and apply various filters on them for image processing.
However I cannot even detect the devices with twaingui_demo. Only thing I can detect is my scanner (which does not help of course). It doesn't even detect a USB device attached.
So what exactly am I doing wrong?
PS. I want my code to also work in 32bit OSes. Would that pose a problem?
|
|
|
|
|
|
There is a 64-bit version of the same DLL??
thanks
|
|
|
|
|
Hi All,
I have this code in vb.net 05 and its working very well,however at the following line I got type mismatche..any knows how to fix that?
bmi.biSizeImage = Int((((bmi.biWidth * bmi.biBitCount) + 31) & Hex(Not (31))) / 2 ^ 3) * bmi.biHeight
error message after scanning - cannot convert string {"HEXNUMBER"} to double.
??
help me please.
thanks
|
|
|
|
|
Try to change with:
bmi.biSizeImage = Int((((bmi.biWidth * bmi.biBitCount) + 31) And (Not (31))) >> 3) * bmi.biHeight
|
|
|
|
|
How to used scanner in vs2008 aspx
|
|
|
|
|
Dear author
thanks for your help
After playing with your code I thought that it would be great to have a component to just drag and drop on the form. I found TwainNET and some other but they are not good enough. To get a good one you have to pay. Do u know any good open source component library. Or may be we should create one.ilme talib
|
|
|
|
|
hello,
I am trying to save image to particular folder without opening any dialog box.My application scan multiple images and after scanning it ask for every image to save but i want to fix it to static folder without opening any save dialog box.(i am not using "picform" to show picture)
My Code as follow.
So can u help me, what modification i have to do ..
case TwainCommand.TransferReady:
{
ArrayList pics = tw.TransferPictures();
int i;
EndingScan();
tw.CloseSrc();
for (i = 0; i <= pics.Count - 1; i += 1)
{
IntPtr img = (IntPtr)pics[i];
PicForm newpic = new PicForm(img);
newpic.Text = "PicNo " + picnumber.ToString();
picnumber = picnumber + 1;
Gdip.SaveDIBAs(newpic.Text, GlobalLock(img), GetPixelInfo(GlobalLock(img)));
//If you saved that image remove the image in the memory
Marshal.FreeHGlobal(img);
// under System.Runtime.InteropServices namespace
Gdip.GdipDisposeImage(img);
newpic.Close();
}
break;
}
|
|
|
|
|
hello ,
i got solution for my own problem ..so its ok ...
|
|
|
|
|
create a variable content a path for you folder
Dim FileName As String
FileName = "C:\Ciao\" & picname & ".bmp"
Comment the code for ShowInputDialog
Pass a variable FileName
st = GdipSaveImageToFile(img, FileName, clsid, IntPtr.Zero)
|
|
|
|
|
|
|
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.
|
|
|
|
|