Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WIA Setting up page size does not work

$
0
0

Im trying to make an app that can scan documents using C# and WIA. But I have come across a problem when setting up the page size property. When I run the scanning process my app throws an error:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in DigiKnjiga.exe

Additional information: Exception from HRESULT: 0x80210067

I have tried this using these properties: PageSize(3097), PageWidth(3098) & PageHeight(3099), HorizontalExtent(6151) & VerticalExtent(6152). But setting any of these values throws the before mentioned exception.

Here is the event that starts the scanning process:

private void scanNew_Click(object sender, EventArgs e)
    {
        if (Scanner.ChosenDevice > 0)
        {
            Device = deviceManager.DeviceInfos[Scanner.ChosenDevice].Connect();

            switch (Scanner.ColorCode)
            {
                case 0://color
                    Device.Items[1].Properties["6146"].set_Value(1);
                    break;
                case 1://grayscale
                    Device.Items[1].Properties["6146"].set_Value(2);
                    break;
                case 2://black and white
                    Device.Items[1].Properties["6146"].set_Value(4);
                    break;
            }

            //(DPI)
            Device.Items[1].Properties["6147"].set_Value(Scanner.DPI);
            Device.Items[1].Properties["6148"].set_Value(Scanner.DPI);

            //brightness
            Device.Items[1].Properties["Brightness"].set_Value(Scanner.Brightness);

            //contrast
            Device.Items[1].Properties["Contrast"].set_Value(Scanner.Contrast);

            switch (Scanner.Format)
            {
                case 0://A3
                    Device.Items[1].Properties["3097"].set_Value(10);
                    //Device.Items[1].Properties["6151"].set_Value(11692);
                    //Device.Items[1].Properties["6152"].set_Value(16535);
                    break;
                case 1://A4
                    Device.Items[1].Properties["3097"].set_Value(0);
                    //Device.Items[1].Properties["6156"].set_Value(1);
                    //Device.Items[1].Properties["3098"].set_Value(8267);
                    //Device.Items[1].Properties["3099"].set_Value(11692);
                    ////Device.Items[1].Properties["6151"].set_Value(1165 * 2);
                    ////Device.Items[1].Properties["6152"].set_Value(1653 * 2);
                    ////Device.Items[1].Properties["3097"].set_Value("0");
                    break;
                case 2://A5
                    Device.Items[1].Properties["3097"].set_Value(11);
                    //Device.Items[1].Properties["6151"].set_Value(1165);
                    //Device.Items[1].Properties["6152"].set_Value(1653);
                    break;
            }

            switch (Scanner.FileType)
            {
                case 0://JPEG
                    image = (WIA.ImageFile)Device.Items[1].Transfer(WIA.FormatID.wiaFormatJPEG);
                    break;
                case 1://PNG
                    image = (WIA.ImageFile)Device.Items[1].Transfer(WIA.FormatID.wiaFormatPNG);
                    break;
                case 2://BMP
                    image = (WIA.ImageFile)Device.Items[1].Transfer(WIA.FormatID.wiaFormatBMP);
                    break;
                case 3://TIFF
                    image = (WIA.ImageFile)Device.Items[1].Transfer(WIA.FormatID.wiaFormatTIFF);
                    break;
            }

            byte[] imageBytes = (byte[])image.FileData.get_BinaryData();
            MemoryStream ms = new MemoryStream(imageBytes);
            Image image2 = Image.FromStream(ms);

            Bitmap smaller= new Bitmap(image2 , new Size(prikazZbirke.Width, prikazZbirke.Height));
            prikazStrani.Size = new System.Drawing.Size(image2 .Width, image2 .Height);
            prikazStrani.Location = new Point(0, 0);
            prikazStrani.Image = image2 ;
            image2 .Save("test.jpg");
        }
    }
I wonder if anyone knows the solution to the this problem and I thank you in advance for your answers. And at the same time apologise for any spelling mistakes as I am not english.



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>