简体   繁体   English

C#WIA设置的分辨率不会增加分辨率,而是会增加图像的宽度和高度。 在C#中

[英]C# WIA set resolution doesnt increase resolution instead increases image width and height. in C#

i am trying to scan a document/photo using WIA (Windows Image Acquisition Library v2.0) in C#, but when i increase resolution it doesn't increase the resolution instead increases width and height of the image, but the resolution stays the same. 我正在尝试使用C#中的WIA(Windows图像采集库v2.0)扫描文档/照片,但是当我提高分辨率时,它不会提高分辨率,而是会增加图像的宽度和高度,但是分辨率保持不变。 (Default dpi of the scanner is 75 dpi) ImageFile variable always has 96 dpi. (扫描仪的默认dpi为75 dpi) ImageFile变量始终为96 dpi。

eg. 例如。 if at default dpi 75, image has width and height of 100 then if i set dpi to 150, image will have width and height of 200. but the resulting ImageFile always has 96 dpi regardless of dpi i have set. 如果在默认dpi 75下,图像的宽度和高度为100,那么如果我将dpi设置为150,则图像的宽度和高度为200。但是无论我设置了什么dpi,生成的ImageFile始终具有96 dpi。

            WIA.ImageFile img = null;
            WIA.Item Item = WiaDev.Items[1] as WIA.Item;


            try
            {
                Item.Properties.get_Item("4104").set_Value(24);
                Item.Properties.get_Item("6146").set_Value(1);


                double OrigResolution = Convert.ToDouble(Item.Properties["6147"].get_Value().ToString());
                double ResDiff = 0.0;
                int width = 0, height = 0;
                if (OrigResolution < dpi)
                {
                    ResDiff = 150 / OrigResolution;
                    width = (int)Math.Floor((Convert.ToDouble(Item.Properties["6151"].get_Value().ToString()) * ResDiff));
                    height = (int)Math.Floor((Convert.ToDouble(Item.Properties["6152"].get_Value().ToString()) * ResDiff));

                    Item.Properties["6149"].set_Value(0);
                    Item.Properties["6150"].set_Value(0);

                    Item.Properties.get_Item("6147").set_Value(dpi.ToString("0.0"));
                    Item.Properties.get_Item("6148").set_Value(dpi.ToString("0.0"));

                    Item.Properties["6151"].set_Value(width);
                    Item.Properties["6152"].set_Value(height);
                }

                img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, WIA.FormatID.wiaFormatJPEG, false);
                img.SaveFile("D:\\Test.jpg");

Here is the sample example , you can try according to it 这是示例示例,您可以根据需要尝试

private void setItem(IItem item, object property, object value)
   {
       WIA.Property aProperty = item.Properties.get_Item(ref property);
       aProperty.set_Value(ref value);
   }



   internal bool Scan(bool flatBed)
   {

       WIA.DeviceManager manager = new DeviceManager();
       bool result = false;
       object something = 1;
       object somethingElse;
       WIA.Device scanner = manager.DeviceInfos.get_Item(ref something).Connect();
       IItem item = scanner.Items[1];
      setItem(item, "6146", 4);
       setItem(item, "6147", 200);
       setItem(item, "6148", 200);
       setItem(item, "6151", 200 * 8.5);
       setItem(item, "6152", 200 * 11);
   }

The first setItem is the color [4 black and white, 2 grayscale, 1 color, 0 unspecified] The second is horizontal resolution. 第一个setItem是颜色[4个黑白,2个灰度,1个颜色,0个未指定],第二个是水平分辨率。 The third is veritcal resolution. 第三是纵向分辨率。 The fourth is horizontal scanning area. 第四个是水平扫描区域。 The fifth is vertical scanning area. 第五个是垂直扫描区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM