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