且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

扫描后无法在图片框控件中显示图像

更新时间:2023-11-03 09:47:10

请看这里,http://channel9.msdn.com/coding4fun/articles/Look-at-me-Windows-图像采集 [ ^ ]



几乎总结了它

Please have a look here,http://channel9.msdn.com/coding4fun/articles/Look-at-me-Windows-Image-Acquisition[^]

that pretty much sums it up
tem item = device.ExecuteCommand(CommandID.wiaCommandTakePicture);
foreach (string format in item.Formats)
{
    if (format == jpegGuid)
    {
        WIA.ImageFile imagefile = item.Transfer(format) as WIA.ImageFile;
        filename = GetFreeFileName();
        if (string.IsNullOrEmpty(filename) == false)
        {
//Instead of saving  get it to the picture box (you should know how to convert it to Image object
            imagefile.SaveFile(filename);
        }
        this.picLastImage.Load(filename);
        return filename;
    }
}


private void button2_Click(object sender, EventArgs e)
{
    const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
    CommonDialogClass wiaDiag = new CommonDialogClass();
    WIA.ImageFile wiaImage = null;

    wiaImage = wiaDiag.ShowAcquireImage(
            WiaDeviceType.UnspecifiedDeviceType,
            WiaImageIntent.GrayscaleIntent,
            WiaImageBias.MaximizeQuality,
            wiaFormatJPEG, true, true, false);

    WIA.Vector vector = wiaImage.FileData;

    Image i = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));
    i.Save(@"D:\prueba1.jpeg");
}





最终解决方案完美无缺。



Final solution works perfectly.