WIA Automation for scanner color intent is not working

Posted by Mike Nicholson on Stack Overflow See other posts from Stack Overflow or by Mike Nicholson
Published on 2009-06-28T19:30:50Z Indexed on 2010/05/01 1:17 UTC
Read the original article Hit count: 639

Filed under:
|
|
|
|

I cannot get my Canon Pixma MP150 to scan a color scan from c# code. The following code is resulting in a black and white image, or if I change the value of 6146 to 2 then a grayscale image is created. I would like to be able to have a color scan from code. I know the scanner does color images because I can do one through the xp wizard in "scanners and camera". Can anyone help me figure out what value I am not setting for a color scan. All documentation and examples I can find just say to change the value of 6146.

Thank you for taking the time to read this!

    private void ScanAndSaveOnePage ()
    {
        WIA.CommonDialog Dialog1 = new WIA.CommonDialogClass();
        WIA.DeviceManager DeviceManager1 = new WIA.DeviceManagerClass();
        System.Object Object1 = null;
        System.Object Object2 = null;
        WIA.Device Scanner = null;

        Scanner = Dialog1.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, false, false);

        WIA.Item Item1 = Scanner.Items[1];

        setItem(Item1, "6146", 1);
        setItem(Item1, "6147", 150);
        setItem(Item1, "6148", 150);
        setItem(Item1, "6151", 150 * 8.5);
        setItem(Item1, "6152", 150 * 11);

        WIA.ImageFile Image1 = new WIA.ImageFile();
        WIA.ImageProcess ImageProcess1 = new WIA.ImageProcess();
        Object1 = (Object)"Convert";
        ImageProcess1.Filters.Add(ImageProcess1.FilterInfos.get_Item(ref Object1).FilterID, 0);

        Object1 = (Object)"FormatID";
        Object2 = (Object)WIA.FormatID.wiaFormatBMP;
        ImageProcess1.Filters[1].Properties.get_Item(ref Object1).set_Value(ref Object2);

        Object1 = null;
        Object2 = null;

        Image1 = (WIA.ImageFile)Item1.Transfer(WIA.FormatID.wiaFormatBMP);

        string DestImagePath = @"C:\test.bmp";
        File.Delete(DestImagePath);
        Image1.SaveFile(DestImagePath);
    }

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about printing