Home › Forums › TWAIN Classic › C# Get and Set DPI Resolution
- This topic has 2 replies, 2 voices, and was last updated 11 years, 6 months ago by damiano.canonico.
- AuthorPosts
Hi, I developed an application that scans documents using various scanners and each time I have to show the scanner setting form (ShowUI=1).
I’d like to gather the information about the scanning resolution set, save them and rewrite them next time the software is launched.
I’ve read something around and came up to the following code:[DllImport(“twain_32.dll”, EntryPoint = “#1”)]
private static extern TwRC DSM_Entry([In, Out] TwIdentity origin, IntPtr zeroptr, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwIdentity idds);TwRC rc1 = DSM_Entry(appid, IntPtr.Zero, TwDG.Control, TwDAT.Capability, TwMSG.GetCurrent, srcds);
run just after the scan procedure in the standard TwainLib.cs (appid and srcds are filled as usual) but any time ti gives me failure
I Tested also the following code to set the resolution:TwRC rc1;
TwCapability tc;
TwFix32 f32 = new TwFix32();
f32.FromFloat(100);//value of DPI
tc = new TwCapability(TwCap.IXResolution, f32.Whole);
rc1 = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, tc);
if (rc1 != TwRC.Success)
{
CloseSrc();
return ;
}But it also gives me a TwRC.Failure
Can somebody help me please?
P.S. The scanner I’m using is an HP ScanJet 7650 (maybe it has to do with the scanner)
Hello,
The scanner you are using does not support 100 DPI. Our group suggests that you try using 150.
Best regards,
Hilary Minugh
TWAIN AdministratorOK…I was able to use the Get, I took away to another function the all procedure that now is:
f32.FromFloat(value of DPI );//value of DPI
tc = new TwCapability(TwCap.IXResolution, f32.Whole);
Init(hwnd);
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds);rc1 = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.GetCurrent, tc);
if (rc1 == TwRC.Success)
{
Tw_Enum twResolutions = (Tw_Enum)Marshal.PtrToStructure(GlobalLock(tc.Handle), typeof(Tw_Enum));
}
rc1 = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, tc);Now the TwMSG.Set works (I’m using its value) but I have strange values in the twResolutions fields:
CurrentIndex=0
DefaultIndex=108
ItemType=7
NumItem=300
ItemList is an array of 100 values with stranger valuesIf I use the TwMSG.Get I have in twResolutions :
CurrentIndex=0
DefaultIndex=600
ItemType=7
NumItem=50
ItemList is an array of 100 values with stranger valuesI’m not able to understand how to use one of this values other than set the current value for the resolution
Any Help??- AuthorPosts