|
Thx for the answer
On what page of the specification is this descriped?
|
|
|
|
|
In the Spec1_9_197.pdf in chapter 3, inside "Application Implementation," there is a subsection called "Controlling a TWAIN Session from Your Application." It's on page 39 of the 552 page document. There are some examples written in C. I haven't had time to look at this in detail yet. However, I have to develop a scanning program for a client as will use this section as a guide for the project.
|
|
|
|
|
Give me the message or email if you got this article.
Email me: ltrankhanh@gmail.com
thank.
|
|
|
|
|
Does anybody happen to have this converted to a dll, or have info on how to go about this, I'm just wanting to add simple scanning to my program. I know atalasoft has one, but of course there is the money factor. It'd be nice to just import a dll to my project to do all the scanning.
Thanks in advance
|
|
|
|
|
Hi,
open a new dll project. insert the 3 cs files.
build the project.
open a new windows forms project and insert the dll.
use a MDI app.
get a relevant code from the sample Project and insert it in your app.
build it
that's all .... have a nice day.
Asterix 
|
|
|
|
|
OK
But what 3 files must I include?
And how to use scanner function in my program (which will use this dll) ?
Thanks for answers.
--
Best Regards - Krzysztof K. (KK)
http://auta-prl.prv.pl
http://cpu-museum.prv.pl
|
|
|
|
|
Hi,
Im a newbie and the script is very good. I programed a MDI-App and integrated the scan-script into my app - like this example. But, when the Image is scanned, it create a rectangle on the background from the mdi-child.
What should I do(and where in the MDI-child-code), to get the image(Rectangle) into a PictureBox?
thanks for help.
Asterix 
|
|
|
|
|
.net does't have any suport for converting the returned image to a suitable image format for picture box. i got around the problem by saving the image to a tempory jpeg file and the calling the imagebox method loadImageFromFile
If there is a better way i would like to know of it.
hope this helps
|
|
|
|
|
I'm having the same problem. How did you managed to convert it to jpeg? It would do at least in my case. Can you please provide sample code?
Many thanks in advance.
ZaX
|
|
|
|
|
The code below was taken from my program, the only alteration i have done to the code below was to simlify the filename string. Also my program could only transfer One image at a time so the for loop would need modifying if more than one image is transfered.
Hope this helps.
regards The Amature
[DllImport("gdi32.dll", ExactSpelling=true)]
internal static extern int SetDIBitsToDevice( IntPtr hdc, int xdst, int ydst, int width, int height, int xsrc, int ysrc, int start, int lines,
IntPtr bitsptr, IntPtr bmiptr, int color );
[DllImport("kernel32.dll", ExactSpelling=true)]
internal static extern IntPtr GlobalLock( IntPtr handle );
[DllImport("kernel32.dll", ExactSpelling=true)]
internal static extern IntPtr GlobalFree( IntPtr handle );
[DllImport("kernel32.dll", CharSet=CharSet.Auto) ]
public static extern void OutputDebugString( string outstr );
[DllImport("gdiplus.dll", ExactSpelling=true)]
internal static extern int GdipCreateBitmapFromGdiDib( IntPtr bminfo, IntPtr pixdat, ref IntPtr image );
[DllImport("gdiplus.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]
internal static extern int GdipSaveImageToFile( IntPtr image, string filename, [In] ref Guid clsid, IntPtr encparams );
ArrayList pics = tw.TransferPictures();
EndingScan();
tw.CloseSrc();
picnumber++;
for( int i = 0; i < pics.Count; i++ )
{
IntPtr image = (IntPtr) pics[ i ];
string fileName = @"C:\temp\FileName.JPG" ;
Guid clsid ;
if (!GetCodecClsid(fileName, out clsid))
{
return ;
}
IntPtr bmpptr = GlobalLock(image) ;
IntPtr pixptr = GetPixelInfo(bmpptr) ;
int st = GdipCreateBitmapFromGdiDib(bmpptr, pixptr, ref image) ;
if (File.Exists(fileName)== true)
File.Delete(fileName) ;
st = GdipSaveImageToFile(image, fileName, ref clsid, IntPtr.Zero) ;
this.pictureBox1.Image = Image.FromFile(fileName);
int picnum = i + 1;
GlobalFree(bmpptr) ;
}
|
|
|
|
|
I had left out the following code i do apologize for this
The Amature
using System.Drawing.Imaging ;
private ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
private bool GetCodecClsid( string filename, out Guid clsid )
{
clsid = Guid.Empty;
string ext = Path.GetExtension( filename );
if( ext == null )
return false;
ext = "*" + ext.ToUpper();
foreach( ImageCodecInfo codec in codecs )
{
if( codec.FilenameExtension.IndexOf( ext ) >= 0 )
{
clsid = codec.Clsid;
return true;
}
}
return false;
}
protected IntPtr GetPixelInfo( IntPtr bmpptr )
{
bmi = new BITMAPINFOHEADER();
Marshal.PtrToStructure( bmpptr, bmi );
bmprect.X = bmprect.Y = 0;
bmprect.Width = bmi.biWidth;
bmprect.Height = bmi.biHeight;
if( bmi.biSizeImage == 0 )
bmi.biSizeImage = ((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3) * bmi.biHeight;
int p = bmi.biClrUsed;
if( (p == 0) && (bmi.biBitCount <= 8) )
p = 1 << bmi.biBitCount;
p = (p * 4) + bmi.biSize + (int) bmpptr;
return (IntPtr) p;
}
[StructLayout(LayoutKind.Sequential, Pack=2)]
internal class BITMAPINFOHEADER
{
public int biSize = 0;
public int biWidth = 0;
public int biHeight = 0;
public short biPlanes = 0;
public short biBitCount = 0;
public int biCompression = 0;
public int biSizeImage = 0;
public int biXPelsPerMeter = 0;
public int biYPelsPerMeter = 0;
public int biClrUsed = 0;
public int biClrImportant = 0;
}
|
|
|
|
|
Como no soy de habla inglesa trato de traducir lo esencial.
Prueba esto.
(I translate de essentials.
Try this)
Yo se lo adicioné al código del demo, adicionando un PictureBox al MDIChild.
(I add this to demo code, adding a pictureBox to MDIChild)
Si revisas bien, verás que la funcion devuelve un Bitmap de GDI+, asignable a la propiedad Image del PictureBox, por lo que no hace falta guardarlo temporalmente en ningún archivo en disco. Como parámetros de entrada y variables, empleo las que se emplean en el código suministrado.
(Function returns GDI+ Bitmap, an you can assign this to Image property in PictureBox)
¿de donde saqué la idea? Revisa las instrucciones que envían la imagen hacia el MDIChild, y verás la similitud. (Busca donde aparezca la llamada a la función SetDIBitsToDevice(....) empleada también en mi código.
(I found the hint looking at code, where is the call to SetDIBitsToDevice(....) function, there is the key)
!!!! Que resuelvas !!!! (si no has resuelto)
// El código comienza aquí.
public Bitmap ImgToBitmap(IntPtr dibhandp, TwainLib.TwImageInfo vImageInfo)
{
bmprect = new Rectangle( 0, 0, 0, 0 );
dibhand = dibhandp;
bmpptr = GlobalLock( dibhand );
pixptr = GetPixelInfo( bmpptr );
ImageInfo=vImageInfo;
Bitmap TempBMP=new Bitmap(bmprect.Width, bmprect.Height);
TempBMP.SetResolution(vImageInfo.XResolution,vImageInfo.YResolution);
Graphics TempGrap=Graphics.FromImage(TempBMP);
IntPtr hdc = TempGrap.GetHdc();
SetDIBitsToDevice( hdc, 0, 0, bmprect.Width, bmprect.Height,
0,0, 0, bmprect.Height, pixptr, bmpptr, 0 );
TempGrap.ReleaseHdc(hdc);
TempGrap.Dispose();
GlobalFree( dibhand );
dibhand = IntPtr.Zero;
return(TempBMP);
}
Yo por mi parte busco información de cómo pasarle al escaner los parámetros del Frame, osea, escanear sólo una parte de la imagen. El código, en C#.
( Iam looking for information about how to pass frame parameters to scanner, to scan only a part of the image in glass scanner. Code in C#)
¿Puedes ayudarme?
)Can you help me.)
xxx
|
|
|
|
|
hi
i want to know which part of this project distinguish scanner.because i wnat to make a program that only know every scanner with its resolution and color .
who can help me?
|
|
|
|
|
hi i want to make a project with vc#.net that it could know (distinguish) the scanners whitch we connected.
for example in the FORM we have 3 ComboBox that in first is the name of scanners ans in second is their resolution and last is about their color.
when we select one scanner who is connected i want to project khow it.
who can help me completly from first?
thanks for help.
|
|
|
|
|
i mean help in knowing scanners in vc#.net.this is befor step of scannig the image.plz help me
thanks
|
|
|
|
|
Hi every one
I want to capture image form webcam using Twian in C#
if any one has knowledge about it
Please contact to me
Thanks
Rubab
Rubab
|
|
|
|
|
searching for "DSHOW.NET" and "DIRECTX" on codeproject will help
- sci
|
|
|
|
|
Thanks for reply
actualy i want to use Twain
|
|
|
|
|
Hi,
You can do follow all steps as below:
1, Download TWAIN driver of your webcam.
2, Download source of sample(.NET TWAIN image scanner). After that, edit method "Acquire()" in TwainLib class as below:
//TwCapability cap = new TwCapability( TwCap.XferCount, 10 );
//rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap );
//if (rc != TwRC.Success)
//{
// CloseSrc();
// return;
//}
and run it
I hope it will help you.
|
|
|
|
|
Hi, Can you help me with this ptoblem: is there any possibility, how to set quality of acquired (and then saved) JPEG image? I can change quality before each image transfer (in acquire image wizard of scanner driver), but I want to set it as default!
Thanks in advance.
|
|
|
|
|
Works great!
But is there a way to set the scanner resolution?
|
|
|
|
|
this doesn't work with my scanner:
val = 0 : the result is Success
val > 0 : the result is not Success
public bool SetScanBrightness(short val )
{
TwCapability cap = new TwCapability( TwCap.ICAP_BRIGHTNESS, val );
TwRC rc = DScap(appid, srcds , TwDG.Control, TwDAT.Capability, TwMSG.MSG_SET, cap);
if( rc == TwRC.Success)
return true;
else
return false;
}
public bool SetScanContrast(short val )
{
TwCapability cap = new TwCapability( TwCap.ICAP_CONTRAST, val );
TwRC rc = DScap(appid, srcds , TwDG.Control, TwDAT.Capability, TwMSG.MSG_SET, cap);
if( rc == TwRC.Success)
return true;
else
return false;
}
public bool SetScanDpi(short x, short y)
{
TwCapability capx = new TwCapability( TwCap.ICAP_XRESOLUTION, x );
TwRC rcx = DScap(appid, srcds , TwDG.Control, TwDAT.Capability, TwMSG.MSG_SET, capx);
TwCapability capy = new TwCapability( TwCap.ICAP_YRESOLUTION, y );
TwRC rcy= DScap(appid, srcds , TwDG.Control, TwDAT.Capability, TwMSG.MSG_SET, capy);
if( rcx == TwRC.Success && rcy == TwRC.Success )
return true;
else
return false;
}
|
|
|
|
|
Hi,
I want to get all the scanner default capabilities, but the values are strangely wrong.
Is it from type struct ? How can i receive the correct values ?
Any ideas ?
public int GetOrientation()
{
return GetScannerOneValue(TwCap.ICAP_ORIENTATION);
}
public int GetDuplex()
{
return GetScannerOneValue(TwCap.CAP_DUPLEX);
}
public void GetScanDpi(ref int X, ref int Y)
{
X = GetScannerOneValue(TwCap.ICAP_XRESOLUTION);
Y = GetScannerOneValue(TwCap.ICAP_YRESOLUTION);
}
public int GetScanContrast()
{
return GetScannerOneValue(TwCap.ICAP_CONTRAST);
}
private int GetScannerOneValue(TwCap TwCapType)
{
TwRC rc;
TwCapability cap = new TwCapability( TwCapType, (short) TwOn.One );
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.MSG_GETCURRENT, cap );
if( rc == TwRC.Success )
{
IntPtr inptr = (IntPtr) GlobalLock(cap.Handle);
int scanvalue = Marshal.ReadInt32(inptr);
GlobalUnlock(cap.Handle);
GlobalFree(cap.Handle);
return scanvalue;
}
return 0;
}
|
|
|
|
|
I've been having the same problem. I can't get any values from the source. I checked the manual and it appears as though DSM_Entry is used to change caps, but NetMaster used DS_Entry in DScap... I'm not sure if his code works because I have no way of testing how to set caps either.
Also, you might want to make sure you're accessing the right location in memory. I recall something about the integer scanValue being located 2 bytes after the pointer because it starts with a different variable.
|
|
|
|
|
yes, should be:
int scanvalue = Marshal.ReadInt32(inptr, 2);
|
|
|
|
|