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);
}
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()));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With