有人可以告诉我如何使用WIA从我的相机拍摄最后拍摄的照片的预览图像吗?
这就是拍照所需的一切:
//select device
WIA.CommonDialog dialog = new WIA.CommonDialog();
WIA.Device camera = dialog.ShowSelectDevice(WIA.WiaDeviceType.CameraDeviceType, false, true);
//take picture
camera.ExecuteCommand("{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}");
有了这个我可以获得所有相机属性,但没有最后的图片信息:
string p = "";
foreach (Property p in camera.Properties)
{
p += p.Name + ":\t" + p.get_Value() + "\n";
}
MessageBox.Show(p);
答案 0 :(得分:3)
ExecuteCommand返回一个提供Transfer方法的WIA.Item:
WIA.CommonDialog dialog = new WIA.CommonDialog();
WIA.Device camera = dialog.ShowSelectDevice(WIA.WiaDeviceType.CameraDeviceType, false, true);
WIA.Item takenItem = camera.ExecuteCommand("{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}");
foreach (string formatId in takenItem.Formats)
{
if (Guid.Parse(formatId) == System.Drawing.Imaging.ImageFormat.Jpeg.Guid)
{
WIA.ImageFile wiaImage = takenItem.Transfer(formatId);
var imageData = new MemoryStream( wiaImage.FileData.get_BinaryData());
var image = Image.FromStream(imageData);
//pictureBox1.Image = image;
}
}