Home › Forums › TWAIN Classic › TW_IMAGEINFO
- This topic has 6 replies, 4 voices, and was last updated 9 years, 9 months ago by kgudi.
- AuthorPosts
Hi, I have prepared the following TW_IMAGEINFO structure:
TW_FIX32 resolution;
resolution . Whole = 200;
resolution . Frac = 0;
TW_IMAGEINFO twImageInfo;
twImageInfo . XResolution = resolution;
twImageInfo . YResolution = resolution;
twImageInfo . ImageWidth = 1728;
twImageInfo . ImageLength = 2336;
twImageInfo . SamplesPerPixel = 1;
twImageInfo . BitsPerSample[0] = 1;
twImageInfo . BitsPerSample[1] = 0;
twImageInfo . BitsPerSample[2] = 0;
twImageInfo . BitsPerSample[3] = 0;
twImageInfo . BitsPerSample[4] = 0;
twImageInfo . BitsPerSample[5] = 0;
twImageInfo . BitsPerSample[6] = 0;
twImageInfo . BitsPerSample[7] = 0;
twImageInfo . BitsPerPixel = 1;
twImageInfo . Planar = false;
twImageInfo . PixelType = TWPT_BW;
twImageInfo . Compression = TWCP_NONE;and I use the following triplet to se the values int the scanner’s embedded controller: DG_IMAGE, DAT_IMAGELAYOUT, MSG_SET
Whichever the values I use, I always get a “TWCC_BADVALUE” condition code. Does anybody see which kind of error have I done ?
Thanks from Alvise
Why are you using TW_IMAGEINFO structure with this triplet?
Shouldn’t it be the TW_IMAGELAYOUT structure?I don’t want the user interface to be displayed, and I want to set the resolution and the scanning area programatically.
I have read more accurately paragraph “Changing the Image Attributes” (TWAIN 1.9a spec, page 4-88) and you’re right: TW_IMAGEINFO can’t be used to set scanning parameters using the DG_IMAGE / DAT_IMAGELAYOUT / MSG_SET triplet.
According to that paragraph I should use TW_IMAGELAYOUT, but the contents of this latter structure can’t be used to set the parameters that I need. TW_IMAGEINFO, on the contrary, is exactly the structure containing the parameters that I want to set. And it works: every parameter appears to be properly set. The only problem is that I get the “TWCC_BADVALUE” condition code. That’s all.
I just want to perform one simple task: scan a B&W letter size sheet at 200 dpi and get the uncompressed data. But it appears to be a pretty difficult task using TWAIN.
Regards from Alvise.
@alvise wrote:
TW_IMAGEINFO, on the contrary, is exactly the structure containing the parameters that I want to set.
I just want to perform one simple task: scan a B&W letter size sheet at 200 dpi and get the uncompressed data.
Nevertheless, I’m quite sure that you should use a set of Capability negotiation commands. And yes all of your values in TW_IMAGEINFO structure are legitimate, but as I understand TWAIN doesn’t allow to use SET command with this structure.
@alvise wrote:
I have read more accurately paragraph “Changing the Image Attributes” (TWAIN 1.9a spec, page 4-88) and you’re right: TW_IMAGEINFO can’t be used to set scanning parameters using the DG_IMAGE / DAT_IMAGELAYOUT / MSG_SET triplet.
I think that TW_IMAGEINFO structure can’t be used even with “DG_IMAGE / DAT_IMAGEINFO / MSG_SET” triplet. See same page.
TW_IMAGEINFO can only be Requested. Each Capability has to be set manually
I haven’t figured this out yet but I’m assuming its around the lines….
This is what your IMAGE INFO should look like…
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwImageInfo
{ // TW_IMAGEINFO
public int XResolution;
public int YResolution;
public int ImageWidth;
public int ImageLength;
public short SamplesPerPixel;
// Initialized to 8 Bits (Constant)
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public short[] BitsPerSample;
public short BitsPerPixel;
public short Planar;
public short PixelType;
public short Compression;
}Using this — you would need these capabilities declared
(OF Type ‘TwCap’)ICompression = 0x0100
IPixelType = 0x0101
IBitDepth = 0x112b
IXResolution = 0x1118
IYResolution = 0x1119(I think there is one called IPhysicalHeight, IPhysicalWidth) Still converting.
Then what you would do is use the Triplet :
FIRST You need to get the Memory Location so you use GET
‘cap is set to TypeOf(IBitDepth)
(appid, appid, Control, Capability, Get, cap);
‘change it to what you want it to be –> Then
(appid, appid, Control, Capability, Set, cap);
__________________________________________________________________This is how I understand it. There is some MemLock and Release in there somewhere, I’m still learning the process here too, If anyone can improve upon this answer or at least make it what it should be, I could sure use the help as well
Ben @ Software Innovations
We are facing an issue with scanner, it’s default resolution in twain settings seems through program seems to be high. Trying to set lower resolution with these for TWcap:
IXResolution = 0x1118
IYResolution = 0x1119But what are the valid values I should use? Any help is appreciated.
Thanks
- AuthorPosts