|
Hi, I tried to change the DPI resolution before acquire the image but the call DScap(..) return 'failure'. I'm sure the scanner can support 300dpi. Can anybody help me please??
public enum TwCap : short
{ [...]
// Added this.
ICAP_XRESOLUTION = 0x1118,
ICAP_YRESOLUTION = 0x1119
}
public void Acquire()
{
TwCapability cap = new TwCapability( TwCap.XferCount, 1 );
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap );
if( rc != TwRC.Success )
{
CloseSrc();
return false;
}
//set UNIT to pixel, required by ImageInfo.XResolution (DPI)????
TwCapability unitcap = new TwCapability( TwCap.IUnits, 5 );
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, unitcap );
if( rc != TwRC.Success )
{
CloseSrc();
return false;
}
short Resolution = 300; //Resolution in dpi.
// 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 false;
}
// 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 false;
}
[...]
}
|
|
|
|
|
Hi, several person request me about this problem. I've spoken with them and my idea is that the used Scanner (my was a EPSON 1670) don't expose correctly Twain interface because some Scanners work fine with the same code.
Good luck! 
|
|
|
|
|
Hi, Karol has resolved the problem. Very thanks, Karol!
Karol's hack:
I think I found where the problem lies... In .NETMaster's hack the value
passed to TWAIN functions was always of type Int16 which is definitely a
wrong assumption For example, to set ICAP_XRESOLUTION you should pass
it as Fix32. That's why I've made such changes:
<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 create TwCapability in this way:
<br />
TwCapability capResx = new TwCapability( TwCap.IXResolution, 300, <br />
TwType.Fix32);<br />
Now it works ;-] I will write this solution for all other people having
problems on CodeProject tomorrow [...]
Karol
|
|
|
|
|
Hi
The test program starts out fine and selectmy scanner but as soon as I start scanning it crashes in "public ArrayList.TransferPictures()" on the following line
"rc = dsixfer(appid,srcds,twdg.image.twdat.imagenativexfer,twmsg.get, ref hbitmap );" - line142 in twainLib.cs
Has anyone come across this what can I do to sove it?
|
|
|
|
|
Hai dude,
Actually the code is proper... There is no error... So what error you are getting... Please tell me... Then I can help you...
Raja Chandrasekaran
Dewsoft Solutions
|
|
|
|
|
Hi
I got it to work ... Can't remember what was wrong. Propably some dumb mistake from me.
Thanks for the reply
|
|
|
|
|
Is it possible to start the scan porcess without the source window from the Scannersoftware.
so ony click the "start scanning button" and the rest works in background
Hopefully for some help roland
|
|
|
|
|
The TWAIN specification, which you can download using the link at the top of the article, gives examples of how to do this. The code is written in C.
|
|
|
|
|
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
|
|
|
|
|