如何获取最后一张拍摄的照片

发布于 2025-01-03 22:27:52 字数 527 浏览 1 评论 0原文

有人可以告诉我如何使用 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);

can some tell me how to get a preview image of the last taken picture from my camera with WIA?

This is all you need to take a picture:

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

with this I can get all camera properties, but there is no last picture info:

string p = "";
foreach (Property p in camera.Properties)
{
    p += p.Name + ":\t" + p.get_Value() + "\n";
}
MessageBox.Show(p);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2025-01-10 22:27:52

ExecuteCommand 返回一个 WIA.Item,它提供 Transfer 方法:

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

ExecuteCommand returns a WIA.Item which provide a Transfer method :

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文