質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Q&A

0回答

4404閲覧

Surfaceでスナップショット(静止画)を撮る方法について

k1500

総合スコア12

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

0グッド

0クリップ

投稿2018/08/28 05:10

Surface上で動き、内蔵カメラで静止画を撮るwindows formアプリを開発しています。
AForge.netを用いて作っているのですが、取得したビデオデバイスから
ProvideSnapshotsを見てみるとfalseになり静止画解像度の設定が出来ません。
現状ですと動画をキャプチャして静止画を得る事になってしまい、最大でも
FullHDが限界です。
Surfaceデフォルトのアプリで選択できる8.0MP 4:3(3264x2448)等の解像度で
静止画を撮ることはAForgeで実現する事は不可能なのでしょうか?
お知恵を拝借出来ますと幸いです。```C#
コード

private FilterInfoCollection videoDevices; private VideoCaptureDevice videoDevice; private VideoCapabilities[] videoCapabilities; private VideoCapabilities[] snapshotCapabilities; private SnapshotForm snapshotForm = null; // Main form is loaded private void MainForm_Load( object sender, EventArgs e ) { // enumerate video devices videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice ); if ( videoDevices.Count != 0 ) { // add all devices to combo foreach ( FilterInfo device in videoDevices ) { devicesCombo.Items.Add( device.Name ); } } else { devicesCombo.Items.Add( "No DirectShow devices found" ); } devicesCombo.SelectedIndex = 0; EnableConnectionControls( true ); } // Closing the main form private void MainForm_FormClosing( object sender, FormClosingEventArgs e ) { Disconnect( ); } // Enable/disable connection related controls private void EnableConnectionControls( bool enable ) { devicesCombo.Enabled = enable; videoResolutionsCombo.Enabled = enable; snapshotResolutionsCombo.Enabled = enable; connectButton.Enabled = enable; disconnectButton.Enabled = !enable; triggerButton.Enabled = ( !enable ) && ( snapshotCapabilities.Length != 0 ); } // New video device is selected private void devicesCombo_SelectedIndexChanged( object sender, EventArgs e ) { if ( videoDevices.Count != 0 ) { videoDevice = new VideoCaptureDevice( videoDevices[devicesCombo.SelectedIndex].MonikerString ); EnumeratedSupportedFrameSizes( videoDevice ); } } // Collect supported video and snapshot sizes private void EnumeratedSupportedFrameSizes( VideoCaptureDevice videoDevice ) { this.Cursor = Cursors.WaitCursor; videoResolutionsCombo.Items.Clear( ); snapshotResolutionsCombo.Items.Clear( ); try { videoCapabilities = videoDevice.VideoCapabilities; snapshotCapabilities = videoDevice.SnapshotCapabilities; foreach ( VideoCapabilities capabilty in videoCapabilities ) { videoResolutionsCombo.Items.Add( string.Format( "{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height ) ); } foreach ( VideoCapabilities capabilty in snapshotCapabilities ) { snapshotResolutionsCombo.Items.Add( string.Format( "{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height ) ); } if ( videoCapabilities.Length == 0 ) { videoResolutionsCombo.Items.Add( "Not supported" ); } if ( snapshotCapabilities.Length == 0 ) { snapshotResolutionsCombo.Items.Add( "Not supported" ); } videoResolutionsCombo.SelectedIndex = 0; snapshotResolutionsCombo.SelectedIndex = 0; } finally { this.Cursor = Cursors.Default; } } // On "Connect" button clicked private void connectButton_Click( object sender, EventArgs e ) { if ( videoDevice != null ) { if ( ( videoCapabilities != null ) && ( videoCapabilities.Length != 0 ) ) { videoDevice.VideoResolution = videoCapabilities[videoResolutionsCombo.SelectedIndex]; } if ( ( snapshotCapabilities != null ) && ( snapshotCapabilities.Length != 0 ) ) { videoDevice.ProvideSnapshots = true; videoDevice.SnapshotResolution = snapshotCapabilities[snapshotResolutionsCombo.SelectedIndex]; videoDevice.SnapshotFrame += new NewFrameEventHandler( videoDevice_SnapshotFrame ); } EnableConnectionControls( false ); videoSourcePlayer.VideoSource = videoDevice; videoSourcePlayer.Start( ); } } // On "Disconnect" button clicked private void disconnectButton_Click( object sender, EventArgs e ) { Disconnect( ); } // Disconnect from video device private void Disconnect( ) { if ( videoSourcePlayer.VideoSource != null ) { // stop video device videoSourcePlayer.SignalToStop( ); videoSourcePlayer.WaitForStop( ); videoSourcePlayer.VideoSource = null; if ( videoDevice.ProvideSnapshots ) { videoDevice.SnapshotFrame -= new NewFrameEventHandler( videoDevice_SnapshotFrame ); } EnableConnectionControls( true ); } } // Simulate snapshot trigger private void triggerButton_Click( object sender, EventArgs e ) { if ( ( videoDevice != null ) && ( videoDevice.ProvideSnapshots ) ) { videoDevice.SimulateTrigger( ); } } // New snapshot frame is available private void videoDevice_SnapshotFrame( object sender, NewFrameEventArgs eventArgs ) { Console.WriteLine( eventArgs.Frame.Size ); ShowSnapshot( (Bitmap) eventArgs.Frame.Clone( ) ); } private void ShowSnapshot( Bitmap snapshot ) { if ( InvokeRequired ) { Invoke( new Action<Bitmap>( ShowSnapshot ), snapshot ); } else { if ( snapshotForm == null ) { snapshotForm = new SnapshotForm( ); snapshotForm.FormClosed += new FormClosedEventHandler( snapshotForm_FormClosed ); snapshotForm.Show( ); } snapshotForm.SetImage( snapshot ); } } private void snapshotForm_FormClosed( object sender, FormClosedEventArgs e ) { snapshotForm = null; }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2018/08/28 05:14

ソースコードは、<code>ボタン、’’’の枠の中に貼り付けてください
k1500

2018/08/28 05:15

了解しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問