views:

858

answers:

4

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);
    }
A: 

Hello,

unfortunately I can't help you with this, but did you get any further, do you have more WIA Automation code samples? Thanks in advance!

No, don't have much more to add. I mess around with stuff at night when I feel like it and I have dropped the scanner in favor of building an infrared receiver at the moment. I am sure at some point I will be curious again though. I will update this page when I know more or if the code works on different scanners.
Mike Nicholson
A: 

Hey Mike, did you ever find a resolution for this? I'm having the same problem with a different Canon scanner (CanoScan LIDE 25), but the same code produces a color scan if I use a Dell AIO scanner.

I'm guessing it's a problem with the drivers or the device itself at this point, and I'd be interested if you were ever able to get the darned thing to scan in color.

Grant Watson
A: 

I never really tried too hard past the day I asked this question. I moved on to a different problem and figured someday I would get back to it.

If you are having the same problem then it must be bad Canon drivers. Based upon your info I may buy another scanner (Dell) and try the code. I can always take it back if it does not work.

Thanks!!! At least it lets me know the code is sometimes correct :)

Mike Nicholson
+1  A: 

In case anyone else is wondering, you have to set "4104" as well. By default it was set to 1 bit depth. That did the trick for me.

setItem(Item1, "4104", 24);

In order to find this out, I had to enumerate all the properties and see what they were set to:

foreach (Property propertyItem in item.Properties)
{
    if (!propertyItem.IsReadOnly)
    {
        Console.WriteLine(String.Format("{0}\t{1}\t{2}", propertyItem.Name, propertyItem.PropertyID, propertyItem.get_Value()));
    }
}
Ken
Thanks! That worked!!!!
Mike Nicholson