This project has moved. For the latest updates, please go here.

Setting dpi on the scanner

Jul 2, 2013 at 9:13 PM
When trying to set the dpi to 300 on my scanner it never works, it always leave it set to 96dpi. I check to make sure the scanner can have the dpi set to 300; it can. No matter what I have tried it does not set. the dpi. The scanner is a Fujitsu. Any tips or tricks that will help me get this done?
Coordinator
Jul 3, 2013 at 12:12 PM
Hello, saa3.

To set the dpi, perform the following steps:
  1. Open Data Source Manager (DSM);
  2. Open Data Source (DS)
  3. Set Resolution (dpi);
  4. Acquire image.
The following code shows how to do:
this._twain32.OpenDSM(); // open data source manager
this._twain32.OpenDataSource(); // open data source

#region Get supported resolutions

Twain32.Enumeration _resolutions=this._twain32.GetResolutions();
for(int i=0;i<_resolutions.Count;i++){
    System.Diagnostics.Debug.WriteLine(string.Format("{0:N0} dpi",_resolutions[i]));
}

#endregion

this._twain32.SetResolutions(300f); // set XResolution and YResolution (dpi)
this._twain32.Acquire(); // acquire image
For more information see source code of sample Saraff.Twain.Sample2.
Marked as answer by SARAFF on 6/23/2014 at 12:38 PM
Oct 2, 2013 at 8:57 AM
Hi,

I tried below code but i'm still getting 96 dpi and heigth 3497 and width 2492.
this._twain32.OpenDSM(); // open data source manager
                this._twain32.OpenDataSource(); // open data source
                this._twain32.SetResolutions(150f);
                if((this._twain32.IsCapSupported(TwCap.Duplex)&TwQC.Get)!=0) {
                    var _duplexCapValue=(ushort)this._twain32.GetCap(TwCap.Duplex);
                    if(_duplexCapValue>0) {
                        // 0 - TWDX_NONE
                        // 1 - TWDX_1PASSDUPLEX
                        // 2 - TWDX_2PASSDUPLEX

                        if((this._twain32.IsCapSupported(TwCap.FeederEnabled)&TwQC.Set)!=0) {
                            this._twain32.SetCap(TwCap.FeederEnabled,true);

                            if((this._twain32.IsCapSupported(TwCap.XferCount)&TwQC.Set)!=null) {
                                //this._twain32.SetCap(TwCap.XferCount,-1);

                                if((this._twain32.IsCapSupported(TwCap.DuplexEnabled)&TwQC.Set)!=0) {
                                    this._twain32.SetCap(TwCap.DuplexEnabled,true);
                                }
                            }
                        }
                    }
                }
                var _supportedSizesCap = this._twain32.IsCapSupported(TwCap.SupportedSizes);
                if ((_supportedSizesCap & TwQC.Set) != 0)
                {
                    this._twain32.SetCap(TwCap.SupportedSizes, (ushort)TwSS.A4);
                }
                this._twain32.Acquire();
Coordinator
Oct 2, 2013 at 10:08 AM
Edited Oct 2, 2013 at 4:47 PM
Hello, fatih_senel.
Try this code and tell me what you got.
this._twain32.OpenDSM(); // open data source manager
this._twain32.OpenDataSource(); // open data source
this._twain32.SetResolutions(600f);
this._twain32.Acquire();
Oct 2, 2013 at 10:43 AM
Hi,

It's still same(96 Dpi).
Coordinator
Oct 2, 2013 at 4:47 PM
Hello, fatih_senel.
What was the size of the image?
Oct 30, 2013 at 7:35 PM
Hi,

It's dimensions : 1240x1754 and 96 dpi
Jan 16, 2014 at 4:15 PM
More info:

My tiff image dimensions: 2560 x 3300 which is correct for US letter size paper scanned at 300 dpi, however, when you look at the properties for the image it displays a dpi of 96.
Coordinator
Jan 16, 2014 at 5:13 PM
Hello, saa3.
In the properties for the image displayed dpi for GDI (Graphics Device Interface). Method SetCap sets dpi for scanner, but not for GDI.
Jan 16, 2014 at 5:38 PM
Understood, but, I simply scan the document, than I grab the image using:

Image testImg;
testImg = this._twain32.GetImage(0);
testImg.Save("d:\testImg.tif");


So, I have also tried saving the image directly from the twain object without saving to another image object:
this._twain32.GetImage(0).Save("d:\testImg.tif");

Why is it that the scanner scans at 300 dbi but the image that is stored in the twain object seems to say it is at 96 dbi?

I have stepped through my code checking the objects as I go and the image that is in the _twain32 object reports back 96 dbi, what am I missing?
Coordinator
Jan 16, 2014 at 6:05 PM
Hello, saa3.
var _img = this._twain32.GetImage(0) as Bitmap; 
_img.SetResolution(300,300);
_img.Save(@"d:\testImg.tif",ImageFormat.Tiff); 
Jan 16, 2014 at 6:32 PM
Excellent. That does it. Sorry for being thick as a brick.
I am very happy with the driver and only had the one sticking point.
Jan 17, 2014 at 5:34 AM
Edited Jan 17, 2014 at 5:39 AM
Hello, i have some problem like saa3, but this method don't help me. Resolution remains on 96x96, i can see it.
I have a button and when i click on it, it must scan image and recog. I tried over and over again: twain.OpenDataSource() and SetResolutions(300f) put in MainWindow section, but it doesn't work. And so I wrote this:
private void scan_button_Click(object sender, RoutedEventArgs e)
        {
            twain.OpenDataSource();
            twain.SetResolutions(300f);
            twain.CloseDataSource();
            twain.SelectSource();
            twain.Acquire();
            twain.ShowUI = false;
        }
There's this code In MainWindows section:
 public MainWindow()
        {
            InitializeComponent();
            this.twain.OpenDSM();
            twain.AcquireCompleted += new EventHandler(_AcquireCompleted);
        }
In _AcquireCompleted:
System.Drawing.Image img =  twain.GetImage(0);
            textBox.Text(img.HorizontalResolution.ToString()+ "x" + img.VerticalResolution.ToString());
And textbox write "96x96".
Help me. Thx.
Coordinator
Jan 17, 2014 at 6:08 AM
Hello, DyGer.

Try follow code:
 public MainWindow(){
            InitializeComponent();
            this.twain.OpenDSM();
            this.twain.ShowUI = false;
            twain.AcquireCompleted += new EventHandler(_AcquireCompleted);
        }

private void scan_button_Click(object sender, RoutedEventArgs e){
            this.twain.CloseDataSource();
            this.twain.SelectSource();
            this.twain.OpenDataSource();
            this.twain.SetResolutions(300f);
            this.twain.Acquire();
        }