タイトル : Re: PictureBoxにUSBカメラの画像を表示させる方法 投稿日 : 2006/02/12(Sun) 12:25 投稿者 : YAS
> PictureBoxにUSBカメラの画像を簡単に表示させ、その画像を静止画で ^^^^ DirectShow.NETを使う場合はあまり「簡単」ではないですね。 VB用DirectShowタイプライブラリの公式なものとして ActiveMovie control type libraryがあります。 しかし,たぶんVB6.0用なのだと思います。 参照設定して試してみると,USBカメラの動画をPictureBoxに 表示するところまでは「簡単」にできるのですが, 動画から静止画を切り出すことがうまくできませんでした。 (IBasicVideoインターフェイスのGetCurrentImageメソッドが うまく動作してくれないのです。引数の与え方が違うのかな?) グラフィックアクセラレータのハードウェアアクセラレータを 「無効」にしてしまい,画面コピーで画像をとるという裏技も あります。 .NETで「簡単」な方法はなかなか無いようです。 VB6.0なら結構簡単なのですが... ActiveMovie control type libraryでUSBカメラの動画をPictureBoxに表示する例です。 Imports System.Runtime.InteropServices Imports QuartzTypeLib Public Class Form1 Const DeviceName As String = "Video Blaster WebCam 3/WebCam Plus (WDM)" Const CapturePinName As String = "キャプチャ" Private VideoWindow As New PictureBox Private FM As New FilgraphManager Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Me.VideoWindow.Dock = DockStyle.Fill Me.Controls.Add(Me.VideoWindow) AddFilter(FM, DeviceName) RenderPin(FM, DeviceName, CapturePinName) Dim VW As IVideoWindow = DirectCast(FM, IVideoWindow) With VW .WindowStyle = CInt(&H6000000) .SetWindowPosition(0, 0, Me.VideoWindow.Width, Me.VideoWindow.Height) .Owner = Me.VideoWindow.Handle End With VW = Nothing FM.Run() End Sub Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If FM IsNot Nothing Then Marshal.ReleaseComObject(FM) End Sub 'グラフにフィルタを追加する Private Sub AddFilter(ByVal Graph As FilgraphManager, ByVal FilterName As String) Dim RegFilterCollection As Object = Nothing Dim Filter As IFilterInfo = Nothing Try RegFilterCollection = Graph.RegFilterCollection For Each objFilter As IRegFilterInfo In RegFilterCollection If objFilter.Name = FilterName Then objFilter.Filter(Filter) Exit For End If Next Finally If Filter IsNot Nothing Then Marshal.ReleaseComObject(Filter) If RegFilterCollection IsNot Nothing Then _ Marshal.ReleaseComObject(RegFilterCollection) End Try End Sub 'ピンをレンダリングする Private Sub RenderPin(ByVal Graph As FilgraphManager, _ ByVal FilterName As String, ByVal PinName As String) Dim FilterCollection As Object = Nothing Dim Pins As Object = Nothing Try FilterCollection = Graph.FilterCollection For Each Filter As IFilterInfo In FilterCollection If Filter.Name = FilterName Then Pins = Filter.Pins For Each Pin As IPinInfo In Pins If Pin.Name = PinName Then Pin.Render() Exit For End If Next Exit For End If Next Finally If FilterCollection IsNot Nothing Then Marshal.ReleaseComObject(FilterCollection) If Pins IsNot Nothing Then Marshal.ReleaseComObject(Pins) End Try End Sub End Class |