From: Joe Cool on
I am trying to add some simple scanning code to an app to use my WIA
compliant scanner. I have downloaded and installed the WIAAUT.DLL I
found some sample C#.NET code that uses WIA and have a simple test app
that will invoke my scanner's WIA driver UI that lets me run a preview
scan, mask the area I want to scan, adjust the DPI, etc, and then
scan. All well and good.

Here's the rub. It doesn't matter what value I pass to the FormatID
property, the returned ImageFile object is ALWAYS in Window BMP
format!! I want to save as JPG. But the saved file is always the same
exact length and an image editor says that they are all BMP files.

I have found some code that uses the WIA ImageProcess class that can
convert a BMP file to a JPG file, but why should I have to do that?

Sample Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WIA;

namespace WIAScanner
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
WIA.CommonDialogClass scanner;
ImageFile imageObject;

scanner = new CommonDialogClass();
imageObject = scanner.ShowAcquireImage
(WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent,
WiaImageBias.MinimizeSize,
ImageFormat.Jpeg.Guid.ToString("B"), false, true,
true);
MessageBox.Show(string.Format("File Extension = {0}\n
\nFormat = {1}", imageObject.FileExtension, imageObject.FormatID));
imageObject.SaveFile(@"E:\test.jpg");
MessageBox.Show("Done");
}
}
}
From: David on
Hi,

If you have been reading the group recently, you will have seen that I have
been having WIA problems, but a different set of problems. I am using the
Transfer rather than ShowAcquireImage so that I don't pop-up the scanner
interface and have more buttons to press.

However, I noticed that same issue. I also noticed that I had to
specifically set the resolution of the scanner to get a reasonable file size
as it tended to scan at max resolution. However, as you are using the
interface, it should take your interface details.

I also noticed that if I set the scanner colour settings AFTER I set the
resolution, my resolution settings would also be reset.

I don't have an answer to the problem you are raising, but have accepted
that if I want to ensure it is a jpg and control the compression settings,
then I have to use the filters.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


"Joe Cool" <joecool1969(a)live.com> wrote in message
news:f2dac47a-d321-48a2-ad0b-dbb99f7612d7(a)h2g2000vbd.googlegroups.com...
>I am trying to add some simple scanning code to an app to use my WIA
> compliant scanner. I have downloaded and installed the WIAAUT.DLL I
> found some sample C#.NET code that uses WIA and have a simple test app
> that will invoke my scanner's WIA driver UI that lets me run a preview
> scan, mask the area I want to scan, adjust the DPI, etc, and then
> scan. All well and good.
>
> Here's the rub. It doesn't matter what value I pass to the FormatID
> property, the returned ImageFile object is ALWAYS in Window BMP
> format!! I want to save as JPG. But the saved file is always the same
> exact length and an image editor says that they are all BMP files.
>
> I have found some code that uses the WIA ImageProcess class that can
> convert a BMP file to a JPG file, but why should I have to do that?
>
> Sample Code:
>
> using System;
> using System.Collections.Generic;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Drawing.Imaging;
> using System.Linq;
> using System.Text;
> using System.Windows.Forms;
> using WIA;
>
> namespace WIAScanner
> {
> public partial class Form1 : Form
> {
> public Form1()
> {
> InitializeComponent();
> }
>
> private void button1_Click(object sender, EventArgs e)
> {
> WIA.CommonDialogClass scanner;
> ImageFile imageObject;
>
> scanner = new CommonDialogClass();
> imageObject = scanner.ShowAcquireImage
> (WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent,
> WiaImageBias.MinimizeSize,
> ImageFormat.Jpeg.Guid.ToString("B"), false, true,
> true);
> MessageBox.Show(string.Format("File Extension = {0}\n
> \nFormat = {1}", imageObject.FileExtension, imageObject.FormatID));
> imageObject.SaveFile(@"E:\test.jpg");
> MessageBox.Show("Done");
> }
> }
> }


From: Joe Cool on
On Dec 16, 11:01 am, "David"
<david.colliver.N...(a)revilloc.REMOVETHIS.com> wrote:
> Hi,
>
> If you have been reading the group recently, you will have seen that I have
> been having WIA problems, but a different set of problems. I am using the
> Transfer rather than ShowAcquireImage so that I don't pop-up the scanner
> interface and have more buttons to press.
>
> However, I noticed that same issue. I also noticed that I had to
> specifically set the resolution of the scanner to get a reasonable file size
> as it tended to scan at max resolution. However, as you are using the
> interface, it should take your interface details.
>
> I also noticed that if I set the scanner colour settings AFTER I set the
> resolution, my resolution settings would also be reset.
>
> I don't have an answer to the problem you are raising, but have accepted
> that if I want to ensure it is a jpg and control the compression settings,
> then I have to use the filters.

I have not tested the sample code I found for conversion, but it
appears to just convert BMP (or whatever) to JPG. How do you adjust
the compression settings with the filters?

>
> --
> Best regards,
> Dave Colliver.http://www.AshfieldFOCUS.com
> ~~http://www.FOCUSPortals.com- Local franchises available
>
> "Joe Cool" <joecool1...(a)live.com> wrote in message
>
> news:f2dac47a-d321-48a2-ad0b-dbb99f7612d7(a)h2g2000vbd.googlegroups.com...
>
>
>
> >I am trying to add some simple scanning code to an app to use my WIA
> > compliant scanner. I have downloaded and installed the WIAAUT.DLL I
> > found some sample C#.NET code that uses WIA and have a simple test app
> > that will invoke my scanner's WIA driver UI that lets me run a preview
> > scan, mask the area I want to scan, adjust the DPI, etc, and then
> > scan. All well and good.
>
> > Here's the rub. It doesn't matter what value I pass to the FormatID
> > property, the returned ImageFile object is ALWAYS in Window BMP
> > format!! I want to save as JPG. But the saved file is always the same
> > exact length and an image editor says that they are all BMP files.
>
> > I have found some code that uses the WIA ImageProcess class that can
> > convert a BMP file to a JPG file, but why should I have to do that?
>
> > Sample Code:
>
> > using System;
> > using System.Collections.Generic;
> > using System.ComponentModel;
> > using System.Data;
> > using System.Drawing;
> > using System.Drawing.Imaging;
> > using System.Linq;
> > using System.Text;
> > using System.Windows.Forms;
> > using WIA;
>
> > namespace WIAScanner
> > {
> >    public partial class Form1 : Form
> >    {
> >        public Form1()
> >        {
> >            InitializeComponent();
> >        }
>
> >        private void button1_Click(object sender, EventArgs e)
> >        {
> >            WIA.CommonDialogClass scanner;
> >            ImageFile imageObject;
>
> >            scanner = new CommonDialogClass();
> >            imageObject = scanner.ShowAcquireImage
> > (WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent,
> > WiaImageBias.MinimizeSize,
> >                ImageFormat.Jpeg.Guid.ToString("B"), false, true,
> > true);
> >            MessageBox.Show(string.Format("File Extension = {0}\n
> > \nFormat = {1}", imageObject.FileExtension, imageObject.FormatID));
> >            imageObject.SaveFile(@"E:\test.jpg");
> >            MessageBox.Show("Done");
> >        }
> >    }
> > }
From: David on
This is how I am doing it...

WIA.ImageProcess ImageProcess1 = new WIA.ImageProcess();

Object Ob1 = null;
Object Ob2 = null;

Ob1 = (Object)"Convert";
ImageProcess1.Filters.Add(ImageProcess1.FilterInfos.get_Item(ref
Ob1).FilterID, 0);

Ob1 = (Object)"FormatID";
Ob2 = (Object)WIA.FormatID.wiaFormatJPEG;
ImageProcess1.Filters[1].Properties.get_Item(ref
Ob1).set_Value(ref Ob2);

Ob1 = (Object)"Quality";
Ob2 = ScanQuality;
ImageProcess1.Filters[1].Properties.get_Item(ref
Ob1).set_Value(ref Ob2);

Ob1 = null;
Ob2 = null;

The ScanQuality is a setting I have stored in my app.config file. It is a
value between 1 and 100, the higher the number, the higher the quality (the
lower the compression and the larger the file). I have mine set to 70


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


"Joe Cool" <joecool1969(a)live.com> wrote in message
news:2d00ae98-2632-4fae-9f4c-73491c7c91af(a)t19g2000vbc.googlegroups.com...
On Dec 16, 11:01 am, "David"
<david.colliver.N...(a)revilloc.REMOVETHIS.com> wrote:
> Hi,
>
> If you have been reading the group recently, you will have seen that I
> have
> been having WIA problems, but a different set of problems. I am using the
> Transfer rather than ShowAcquireImage so that I don't pop-up the scanner
> interface and have more buttons to press.
>
> However, I noticed that same issue. I also noticed that I had to
> specifically set the resolution of the scanner to get a reasonable file
> size
> as it tended to scan at max resolution. However, as you are using the
> interface, it should take your interface details.
>
> I also noticed that if I set the scanner colour settings AFTER I set the
> resolution, my resolution settings would also be reset.
>
> I don't have an answer to the problem you are raising, but have accepted
> that if I want to ensure it is a jpg and control the compression settings,
> then I have to use the filters.

I have not tested the sample code I found for conversion, but it
appears to just convert BMP (or whatever) to JPG. How do you adjust
the compression settings with the filters?

>
> --
> Best regards,
> Dave Colliver.http://www.AshfieldFOCUS.com
> ~~http://www.FOCUSPortals.com- Local franchises available
>
> "Joe Cool" <joecool1...(a)live.com> wrote in message
>
> news:f2dac47a-d321-48a2-ad0b-dbb99f7612d7(a)h2g2000vbd.googlegroups.com...
>
>
>
> >I am trying to add some simple scanning code to an app to use my WIA
> > compliant scanner. I have downloaded and installed the WIAAUT.DLL I
> > found some sample C#.NET code that uses WIA and have a simple test app
> > that will invoke my scanner's WIA driver UI that lets me run a preview
> > scan, mask the area I want to scan, adjust the DPI, etc, and then
> > scan. All well and good.
>
> > Here's the rub. It doesn't matter what value I pass to the FormatID
> > property, the returned ImageFile object is ALWAYS in Window BMP
> > format!! I want to save as JPG. But the saved file is always the same
> > exact length and an image editor says that they are all BMP files.
>
> > I have found some code that uses the WIA ImageProcess class that can
> > convert a BMP file to a JPG file, but why should I have to do that?
>
> > Sample Code:
>
> > using System;
> > using System.Collections.Generic;
> > using System.ComponentModel;
> > using System.Data;
> > using System.Drawing;
> > using System.Drawing.Imaging;
> > using System.Linq;
> > using System.Text;
> > using System.Windows.Forms;
> > using WIA;
>
> > namespace WIAScanner
> > {
> > public partial class Form1 : Form
> > {
> > public Form1()
> > {
> > InitializeComponent();
> > }
>
> > private void button1_Click(object sender, EventArgs e)
> > {
> > WIA.CommonDialogClass scanner;
> > ImageFile imageObject;
>
> > scanner = new CommonDialogClass();
> > imageObject = scanner.ShowAcquireImage
> > (WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent,
> > WiaImageBias.MinimizeSize,
> > ImageFormat.Jpeg.Guid.ToString("B"), false, true,
> > true);
> > MessageBox.Show(string.Format("File Extension = {0}\n
> > \nFormat = {1}", imageObject.FileExtension, imageObject.FormatID));
> > imageObject.SaveFile(@"E:\test.jpg");
> > MessageBox.Show("Done");
> > }
> > }
> > }


From: David on
Oops, I forgot a little bit to add to it... once you have set the filter,
you apply it to your scan...

ImageObject = ImageProcess1.Apply(ImageObject);

This has to be done after your scan.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


"Joe Cool" <joecool1969(a)live.com> wrote in message
news:2d00ae98-2632-4fae-9f4c-73491c7c91af(a)t19g2000vbc.googlegroups.com...
On Dec 16, 11:01 am, "David"
<david.colliver.N...(a)revilloc.REMOVETHIS.com> wrote:
> Hi,
>
> If you have been reading the group recently, you will have seen that I
> have
> been having WIA problems, but a different set of problems. I am using the
> Transfer rather than ShowAcquireImage so that I don't pop-up the scanner
> interface and have more buttons to press.
>
> However, I noticed that same issue. I also noticed that I had to
> specifically set the resolution of the scanner to get a reasonable file
> size
> as it tended to scan at max resolution. However, as you are using the
> interface, it should take your interface details.
>
> I also noticed that if I set the scanner colour settings AFTER I set the
> resolution, my resolution settings would also be reset.
>
> I don't have an answer to the problem you are raising, but have accepted
> that if I want to ensure it is a jpg and control the compression settings,
> then I have to use the filters.

I have not tested the sample code I found for conversion, but it
appears to just convert BMP (or whatever) to JPG. How do you adjust
the compression settings with the filters?

>
> --
> Best regards,
> Dave Colliver.http://www.AshfieldFOCUS.com
> ~~http://www.FOCUSPortals.com- Local franchises available
>
> "Joe Cool" <joecool1...(a)live.com> wrote in message
>
> news:f2dac47a-d321-48a2-ad0b-dbb99f7612d7(a)h2g2000vbd.googlegroups.com...
>
>
>
> >I am trying to add some simple scanning code to an app to use my WIA
> > compliant scanner. I have downloaded and installed the WIAAUT.DLL I
> > found some sample C#.NET code that uses WIA and have a simple test app
> > that will invoke my scanner's WIA driver UI that lets me run a preview
> > scan, mask the area I want to scan, adjust the DPI, etc, and then
> > scan. All well and good.
>
> > Here's the rub. It doesn't matter what value I pass to the FormatID
> > property, the returned ImageFile object is ALWAYS in Window BMP
> > format!! I want to save as JPG. But the saved file is always the same
> > exact length and an image editor says that they are all BMP files.
>
> > I have found some code that uses the WIA ImageProcess class that can
> > convert a BMP file to a JPG file, but why should I have to do that?
>
> > Sample Code:
>
> > using System;
> > using System.Collections.Generic;
> > using System.ComponentModel;
> > using System.Data;
> > using System.Drawing;
> > using System.Drawing.Imaging;
> > using System.Linq;
> > using System.Text;
> > using System.Windows.Forms;
> > using WIA;
>
> > namespace WIAScanner
> > {
> > public partial class Form1 : Form
> > {
> > public Form1()
> > {
> > InitializeComponent();
> > }
>
> > private void button1_Click(object sender, EventArgs e)
> > {
> > WIA.CommonDialogClass scanner;
> > ImageFile imageObject;
>
> > scanner = new CommonDialogClass();
> > imageObject = scanner.ShowAcquireImage
> > (WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent,
> > WiaImageBias.MinimizeSize,
> > ImageFormat.Jpeg.Guid.ToString("B"), false, true,
> > true);
> > MessageBox.Show(string.Format("File Extension = {0}\n
> > \nFormat = {1}", imageObject.FileExtension, imageObject.FormatID));
> > imageObject.SaveFile(@"E:\test.jpg");
> > MessageBox.Show("Done");
> > }
> > }
> > }