I've struggled with the limited csharp examples and documentation for WIA for a while now, but I finally have it scanning from an ADF scanner (I will be posting finished code soon as a reference for others wanting to code WIA).
What I'm now stuck with is using the Image Processing. I feel like I am so close yet it's just out of my grasp.
Here is the code I've been currently trying:
Unfortunately the line IP.Filters[1].Properties[Prp] = 50; fails with errors:Code:WIA.ImageProcess IP = new ImageProcessClass(); foreach (FilterInfo F in IP.FilterInfos) { if (F.Name == "Convert") { IP.Filters.Add(F.FilterID,0); foreach (Property Prp in IP.Filters[1].Properties) { if (Prp.Name == "Compression") { //set jpeg compression for image IP.Filters[1].Properties[Prp] = 50; } } } }
Argument '1': cannot convert from 'WIA.Property' to 'ref object' (CS1503)
The best overloaded method match for 'WIA.IProperties.this[ref object]' has some invalid arguments (CS1502)
Obviously I'm not doing it the right way for the properties but the examples on the net are all for VB and I can't seem to convert them to C# (I'm also fairly new to C#)
This is the VB example for creating a filter:
Is anyone able to shed some light on how I can set the properties for the ImageFilter?Code:Dim Img 'As ImageFile Dim IP 'As ImageProcess Set Img = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Bliss.bmp" IP.Filters.Add IP.FilterInfos("Convert").FilterID IP.Filters(1).Properties("FormatID").Value = wiaFormatJPEG IP.Filters(1).Properties("Quality").Value = 5 Set Img = IP.Apply(Img) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\BlissCompressed.jpg"




Reply With Quote