Forum Replies Created
- AuthorPosts
This is, it turns out, to be a limitation of my scanner.
I downloaded Twister from http://www.dosadi.com/twister.htm
and it analyses your scanner. Turns out, mine only supports BMP file downloads. So there was nothing dodgy about the code. The fact that the scanner provider allows scanning to different formats directly, seems to suggest they are bypassing Twain to do this. At least it’s not .NET/the code/me….Altough: I am surprised I cannot save directly as a tiff: from Canon’s own software, it saves to files of different formats including tiff… Or are there other settings to be taken into account when saving to tiff?
If anyone is interested, file conversion in C# from bmp to almost anything is trivial, it turns out:
Bitmap bm = new Bitmap(@”c:pathfile.bmp”);
bm.Save(@”c:pathfile.jpg”, ImageFormat.Jpeg);
bm.Save(@”c:pathfile.tif”, ImageFormat.Tiff);
bm.Save(@”c:pathfile.gif”, ImageFormat.Gif);
bm.Save(@”c:pathfile.png”, ImageFormat.Png);And yes, the dpi resolution is preserved.
Do you have an example of your thread code? And how do you get the dialog to subsequently close, and the scan press to get acted upon?
The reason the DSM_Entry call to SetupFileXfer was failing was because the file format I was trying to create was TIFF. It seems you can have any flavour you want as long as its BMP. I changed the format to BMP, then added a call
rc = DSM_Entry(appid, srcds, TwDG.Image, TwDAT.ImageFileXfer, TwMSG.Get, null);
And the file was created. The resolution of the file is as I want. I may need to convert the file from bmp to jpeg or tiff, but that is pretty straightforward. Thanks to gabe and kaij for your help.
After all that: looking in the Output window, I get Setcapability Icap_ImageFileFormat failure. I somehow suspect the scanner I am using is not upto the job.
On the identity window I get Protocol Major = 1, Minor = 8,
then version Major= 7 and Minor = 0, so is that Twain 1.8 which doesn’t support MSG_ENABLEDSUIONLY.I’ve got another, more recent scanner to play with. After all that…
I remember getting something daft like 11811 – which, if you divide by 39.37 …. something gives 300 – 39.37 inches in a meter.
Thanks for all your help. I have grabbed the download, and will give that a go.
Just changed my TwSetupFileXfers back to :
internal class TwSetupFileXfers
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
//public Byte[] FileName = new Byte[256]; /* File to contain data */
public string FileName = “”;
public UInt16 Format; /* A TWFF_xxxx constant */
public IntPtr VrefNum; /* Used for Macintosh only */
}This STILL returns Failure.
I succeed in setting up the capability via:
TwCapability cap2 = new TwCapability(TwCap.IXferMech, (short) TwXferMech.FILE);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap2);rc returns success.
I still get a failure later on in
rc = DSsetupFileXfer(appid, srcds, TwDG.Control, TwDAT.SetupFileXfer, TwMSG.Set, twsfFile);
Where DSsetupFileXfer is:
[DllImport(“twain_32.dll”, EntryPoint = “#1”)]
private static extern TwRC DSsetupFileXfer([In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, TwSetupFileXfers sfxfr);I have setup TwSetupFileXfers as follows:
internal class TwSetupFileXfers
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public Byte[] FileName = new Byte[256]; /* File to contain data */
public UInt16 Format; /* A TWFF_xxxx constant */
public IntPtr VrefNum; /* Used for Macintosh only */
}How do I get an error message back?
I pumped that code through a VB to C# converter (see http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx)
so it’s easier for me to follow, and got the following:public bool SetXferMech(string value)
{
Enumerations.XferMech xferMechVal;switch (value) {
case Enumerations.XferMech.File.ToString:
xferMechVal = Enumerations.XferMech.File;
break;
case Enumerations.XferMech.Memory.ToString:
xferMechVal = Enumerations.XferMech.Memory;
break;
default:
xferMechVal = Enumerations.XferMech.Native;
break;
}//SetXferMode(_Profile.TransferMode)
////
alias the namespace for shorter calls (not needed, just prettier)
Enumerations.Capability cap_XferMech = Enumerations.Capability.Icap_XferMech;//prep the container
DataStructures.twOneValue XferMechOneval = new DataStructures.twOneValue();
XferMechOneval.ItemType = DataStructures.twCapability.CapType(cap_XferMech);
XferMechOneval.Item = xferMechVal;//create the CapStruc with the container
DataStructures.twCapability capXferMech = new DataStructures.twCapability(cap_XferMech, XferMechOneval);
//set the Cap
bool retBool = OperationTriplets.Control.Capability.Set(capXferMech);
return retBool;
}Where can I download your classes eg. OperationTriplets.Control.Capability.Set – I assume that equates to
DSM_Entry(..,..,Control, Capability, Set, Val);
//OperationTriplets.Control.Capability.Set equates to :Doesn’t the following setup the transfer mode to file?
rc = DSM_Entry(appid, srcds, TwDG.Control, TwDAT.SetupFileXfer, TwMSG.Set, twsfFile);I tried:
rc = DSM_Entry(appid, srcds, TwDG.Control, TwDAT.SetupFileXfer, TwMSG.Set, twsfFile);
where twsfFile is a SetupFileXfers structure.
I am using C#. My SetupFileXfers structure is as follows:
internal class SetupFileXfers
{
/* [MarshalAs( UnmanagedType.ByValArray, SizeConst=256)] – commented out */
public Byte[] FileName = new Byte[256]; /* File to contain data */
public UInt16 Format; /* A TWFF_xxxx constant */
public IntPtr VrefNum; /* Used for Macintosh only */
}I get a Failure report when this is called, but don’t know how to get an error code.
I suspect the structure is wrong?I have posted you the source.
Sorry, typo; I didn’t mean “distinctive” at all. Meant “distinct” as in “clear”, “sharp”.
Where do I post a sample to?XResolution = 300
YResolution = 300- AuthorPosts