Windows Image Acquisition library problems

J

Joe Cool

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");
}
}
}
 
D

David

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
 
J

Joe Cool

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?
 
D

David

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


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?
 
D

David

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


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?
 
T

Tim Roberts

Joe Cool said:
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?

Similar to most architectures like it, a WIA provider is not required to
hand you exactly what you ask for. You ask for what you want, and the WIA
provider gets as close as it can.

Having said that, I'm surprised you can't get JPEG. Almost all WIA
providers do both BMP and JPEG.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top