tagCANDY CGI VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
[ツリー表示へ]  [ワード検索]  [Home]

タイトル Re: デスクトップアプリでWEBカメラを使いたい
投稿日: 2017/11/01(Wed) 23:18
投稿者jikoryuu
http://note.websmil.com/vb/aforge/vb-net-aforge-usb%e3%82%ab%e3%83%a1%e3%83%a9%e7%94%bb%e5%83%8f%e8%a1%a8%e7%a4%ba

このサイトが参考になるかと

これに画像保存を足してみました

AForgeのインストールは
http://robot-factory.blogspot.jp/search/label/%E7%94%BB%E5%83%8F%E5%87%A6%E7%90%86
http://memo.everyday.jp/archives/356
が参考になるかと

ソースは以下

Imports AForge.Video
Imports AForge.Video.DirectShow

Public Class Form1

    Dim _videoSource As VideoCaptureDevice = Nothing

    'ビデオデバイスの起動
    Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
        'ビデオ入力デバイスのみ取得
        Dim videoDevices = New FilterInfoCollection(FilterCategory.VideoInputDevice)
        If videoDevices.Count = 0 Then                        'ビデオデバイスが無い
            Return
        End If

        Dim MonikerString = videoDevices(0).MonikerString     '最初のビデオデバイスを使用

        _videoSource = New VideoCaptureDevice(MonikerString)
        AddHandler _videoSource.NewFrame, AddressOf Me.Video_NewFrame
        _videoSource.Start()
    End Sub

    'ビデオデバイスの停止
    Private Sub StopButton_Click(sender As Object, e As EventArgs) Handles StopButton.Click
        If _videoSource Is Nothing Then
            Return
        End If

        If _videoSource.IsRunning Then
            _videoSource.SignalToStop()     'ビデオデバイスの停止
            _videoSource.WaitForStop()      '完全に停止するまで待つ
            _videoSource = Nothing
        End If
    End Sub

    'ビデオデバイス取得画像表示
    Private Sub Video_NewFrame(sender As Object, eventArgs As NewFrameEventArgs)
        Dim img = DirectCast(eventArgs.Frame.Clone(), Bitmap)
        PictureBox1.Image = img
    End Sub

    '画像を保存
    Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
        PictureBox1.Image.Save("Test.bmp")
    End Sub
End Class

- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。