我正在使用 wia 扫描仪的代码。但是在 75dpi 之后,扫描仪没有给我完整的图像。我从扫描仪中只得到了一半的图像。请检查一下。
private static void SaveImageToPNGFile(ImageFile image, string fileName)
{
ImageProcess imgProcess = new ImageProcess();
object convertFilter = "Convert";
string convertFilterID = imgProcess.FilterInfos.get_Item(ref convertFilter).FilterID;
imgProcess.Filters.Add(convertFilterID, 0);
SetWIAProperty(imgProcess.Filters[imgProcess.Filters.Count].Properties, "FormatID", WIA.FormatID.wiaFormatPNG);
image = imgProcess.Apply(image);
image.SaveFile(fileName);
}
private static void AdjustScannerSettings(IItem scannnerItem, int scanColor,
int scanWidthPixels, int scanHeightPixels, int brightnessPercents, int contrastPercents)
{
SetWIAProperty(scannnerItem.Properties, "4104", 24);
SetWIAProperty(scannnerItem.Properties, "6146", scanColor);
SetWIAProperty(scannnerItem.Properties, "6147", 75);//Horizontal resolution
SetWIAProperty(scannnerItem.Properties, "6148", 75);//vertical resolution
SetWIAProperty(scannnerItem.Properties, "6151", scanHeightPixels);
SetWIAProperty(scannnerItem.Properties, "6152", scanWidthPixels);
SetWIAProperty(scannnerItem.Properties, "6154", brightnessPercents);//range from -100 to 100. 0 refer for the normal brightnes
SetWIAProperty(scannnerItem.Properties, "6155", contrastPercents);//range from -100 to 100. 0 refer for the normal brightnes
}
private static void SetWIAProperty(IProperties properties, object propName, object propValue)
{
Property prop = properties.get_Item(ref propName);
prop.set_Value(ref propValue);
}
private void button1_Click(object sender, EventArgs e)
{
int height = int.Parse(textBoxheight.Text.Trim());
int width = int.Parse(textBoxwidth.Text.Trim());
CommonDialogClass commonDialogClass = new CommonDialogClass();
Device scannerDevice;
try
{
scannerDevice = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false , false);
if (scannerDevice != null)
{
Item scannnerItem = scannerDevice.Items[1];
AdjustScannerSettings(scannnerItem, 4, height, width, 20, 20);//dpi valid only for 150,200,300,400
object scanResult = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatPNG, false);
if (scanResult != null)
{
ImageFile image = (ImageFile)scanResult;
// Image objimg = (Image)image;
string fileName = Path.GetTempPath() + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss-fffffff") + ".png";
SaveImageToPNGFile(image, fileName);
pictureBox1.ImageLocation = fileName;
//pictureBox1.Height = height;
//pictureBox1.Width = width;
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
Bitmap obj = new Bitmap(fileName);
panel1.BackgroundImage = obj;
panel1.AutoSize = true;
panel1.AutoScroll = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button3_Click(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.Hide();
wiascan obj = new wiascan();
obj.Show();
}
}
我尝试在图片框和面板中显示我的图像,但两个控件都无法给我完整的图像。