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);
4

1 に答える 1

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;
    }
}
于 2012-02-09T00:15:14.857 に答える