Home › Forums › TWAIN Classic › Scanning directly into a file
- This topic has 19 replies, 3 voices, and was last updated 16 years, 3 months ago by ZiggyShort.
- AuthorPosts
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.
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.
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?
I dunno, tiif generation in the .net framework seemed similar to any of the other formats native to the machine (to me). There is a little hand waving if you want to create multi frame files but I handle Bmp, Gif, Jpeg, Png & Tiff all the same.
To be fair .Net’s default Gif support is,.. what’s the kind work, lousy? And I don’t go out of my way to provide the quality encoder parameter related to jpg encoding- the default (I think it’s 85%) is sufficient.
The code is in the BitmapManip project and the main method to trace (outside of the ctor) is ‘toFile’. I’d post it here but it isn’t really related to twain and I didn’t do very much more than peice toether a couple of code snippets from codeproject to get it working. If you have a question about it send me an email..
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….- AuthorPosts