diegobill 0 Denunciar post Postado Março 3, 2009 estou precisando fazer um programa para capturar a imagem obtida pela webcam, porém não sei como adicionar a biblioteca avicap, quando tento adicionar aparece "the following components could not be browsed". Depois de adicionado a dll, alguem conhece algum tutorial para aprender a usar ela ?! Compartilhar este post Link para o post Compartilhar em outros sites
quintelab 91 Denunciar post Postado Março 3, 2009 diegobill, seja bem vindo ao Fórum iMasters, de uma olhada em nossas regras: Regras do Fórum iMasters Você já deu uma olhada no site da fabricante? É o melhor a fazer. Abraços... Compartilhar este post Link para o post Compartilhar em outros sites
diegobill 0 Denunciar post Postado Março 4, 2009 desculpa esqueci dizer q estava usando o visual studio 2008 mas isso já era obivio ... procurei pela internet e vi q nao sou o unico com esse problema ! Compartilhar este post Link para o post Compartilhar em outros sites
zeke_ 2 Denunciar post Postado Março 5, 2009 Olá diegobill Tenho um exemplo aqui para você. Foto.Designer.vb <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class foto Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.btnCapturaFoto = New System.Windows.Forms.Button Me.btnIniciaGravacao = New System.Windows.Forms.Button Me.picFoto = New System.Windows.Forms.PictureBox Me.btnParaGravacao = New System.Windows.Forms.Button Me.Label2 = New System.Windows.Forms.Label Me.Label1 = New System.Windows.Forms.Label Me.btnParaCamera = New System.Windows.Forms.Button Me.picImagem = New System.Windows.Forms.PictureBox Me.lstFontesVideos = New System.Windows.Forms.ListBox CType(Me.picFoto, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.picImagem, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'btnCapturaFoto ' Me.btnCapturaFoto.Location = New System.Drawing.Point(339, 323) Me.btnCapturaFoto.Name = "btnCapturaFoto" Me.btnCapturaFoto.Size = New System.Drawing.Size(177, 23) Me.btnCapturaFoto.TabIndex = 27 Me.btnCapturaFoto.Text = "Capturar Foto" Me.btnCapturaFoto.UseVisualStyleBackColor = True ' 'btnIniciaGravacao ' Me.btnIniciaGravacao.Location = New System.Drawing.Point(16, 323) Me.btnIniciaGravacao.Name = "btnIniciaGravacao" Me.btnIniciaGravacao.Size = New System.Drawing.Size(98, 23) Me.btnIniciaGravacao.TabIndex = 25 Me.btnIniciaGravacao.Text = "Iniciar Gravação" Me.btnIniciaGravacao.UseVisualStyleBackColor = True ' 'picFoto ' Me.picFoto.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.picFoto.Location = New System.Drawing.Point(339, 94) Me.picFoto.Name = "picFoto" Me.picFoto.Size = New System.Drawing.Size(177, 184) Me.picFoto.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage Me.picFoto.TabIndex = 26 Me.picFoto.TabStop = False ' 'btnParaGravacao ' Me.btnParaGravacao.Location = New System.Drawing.Point(120, 323) Me.btnParaGravacao.Name = "btnParaGravacao" Me.btnParaGravacao.Size = New System.Drawing.Size(98, 23) Me.btnParaGravacao.TabIndex = 24 Me.btnParaGravacao.Text = "Parar Gravação" Me.btnParaGravacao.UseVisualStyleBackColor = True ' 'Label2 ' Me.Label2.AutoSize = True Me.Label2.Location = New System.Drawing.Point(16, 78) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(83, 13) Me.Label2.TabIndex = 23 Me.Label2.Text = "Visualizar Vídeo" ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Location = New System.Drawing.Point(16, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(98, 13) Me.Label1.TabIndex = 22 Me.Label1.Text = "Dispositivos Fontes" ' 'btnParaCamera ' Me.btnParaCamera.Location = New System.Drawing.Point(224, 323) Me.btnParaCamera.Name = "btnParaCamera" Me.btnParaCamera.Size = New System.Drawing.Size(98, 23) Me.btnParaCamera.TabIndex = 21 Me.btnParaCamera.Text = "Parar Camera" Me.btnParaCamera.UseVisualStyleBackColor = True ' 'picImagem ' Me.picImagem.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.picImagem.Location = New System.Drawing.Point(16, 94) Me.picImagem.Name = "picImagem" Me.picImagem.Size = New System.Drawing.Size(306, 223) Me.picImagem.TabIndex = 20 Me.picImagem.TabStop = False ' 'lstFontesVideos ' Me.lstFontesVideos.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer)) Me.lstFontesVideos.FormattingEnabled = True Me.lstFontesVideos.Location = New System.Drawing.Point(16, 32) Me.lstFontesVideos.Name = "lstFontesVideos" Me.lstFontesVideos.Size = New System.Drawing.Size(500, 43) Me.lstFontesVideos.TabIndex = 19 ' 'foto ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(538, 358) Me.Controls.Add(Me.btnCapturaFoto) Me.Controls.Add(Me.btnIniciaGravacao) Me.Controls.Add(Me.picFoto) Me.Controls.Add(Me.btnParaGravacao) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.btnParaCamera) Me.Controls.Add(Me.picImagem) Me.Controls.Add(Me.lstFontesVideos) Me.Name = "foto" Me.Text = "Capturar Foto" CType(Me.picFoto, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.picImagem, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents btnCapturaFoto As System.Windows.Forms.Button Friend WithEvents btnIniciaGravacao As System.Windows.Forms.Button Friend WithEvents picFoto As System.Windows.Forms.PictureBox Friend WithEvents btnParaGravacao As System.Windows.Forms.Button Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents btnParaCamera As System.Windows.Forms.Button Friend WithEvents picImagem As System.Windows.Forms.PictureBox Friend WithEvents lstFontesVideos As System.Windows.Forms.ListBox End ClassFoto.vb Imports System.Runtime.InteropServices Public Class foto Const WM_CAP_START = &H400S Const WS_CHILD = &H40000000 Const WS_VISIBLE = &H10000000 Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10 Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11 Const WM_CAP_EDIT_COPY = WM_CAP_START + 30 Const WM_CAP_SEQUENCE = WM_CAP_START + 62 Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23 Const WM_CAP_SET_SCALE = WM_CAP_START + 53 Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52 Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50 Const SWP_NOMOVE = &H2S Const SWP_NOSIZE = 1 Const SWP_NOZORDER = &H4S Const HWND_BOTTOM = 1 '--A função capGetDriverDescription retorna a versão do driver de captura Declare Function capGetDriverDescriptionA Lib "avicap32.dll" _ (ByVal wDriverIndex As Short, _ ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _ ByVal cbVer As Integer) As Boolean '--A função capCreateCaptureWindow cria uma janela de captura Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _ (ByVal lpszWindowName As String, ByVal dwStyle As Integer, _ ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _ ByVal nHeight As Short, ByVal hWnd As Integer, _ ByVal nID As Integer) As Integer '--Envia uma mensagem especifica para a janela ou para o Windows Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, _ <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer '--Define a posição da janela relativa ao buffer de tela Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _ (ByVal hwnd As Integer, _ ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _ ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer '--Destroi a janela especificada Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean Dim FonteVideo As Integer Dim hWnd As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Carrega os daados na tabela 'NorthwindDataSet.Employees' btnIniciaGravacao.Enabled = True btnParaGravacao.Enabled = False '---lista todos os dispositivos de video instalados ListaFontesVideo() End Sub '--desconecta da fonte de video Private Sub paraJanelaVisualizacao() SendMessage(hWnd, WM_CAP_DRIVER_DISCONNECT, FonteVideo, 0) DestroyWindow(hWnd) End Sub '---lista todas as fontes de video Private Sub ListaFontesVideo() Dim nomeDriver As String = Space(80) Dim versaoDriver As String = Space(80) For i As Integer = 0 To 9 If capGetDriverDescriptionA(i, nomeDriver, 80, versaoDriver, 80) Then lstFontesVideos.Items.Add(nomeDriver.Trim) End If Next End Sub '---salva a imagem--- Private Sub CapturaImagem() Dim data As IDataObject Dim bmap As Image '---copia a imagem para o clipboard--- SendMessage(hWnd, WM_CAP_EDIT_COPY, 0, 0) '---retorna a imagem do clipboard e a converte para o formato bitmap data = Clipboard.GetDataObject() If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image) picFoto.Image = bmap picFoto.Image.Save("C:\SigClinTemp\foto.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) paraJanelaVisualizacao() End If End Sub '---visualiza a fonte de video selecionada Private Sub VisualizaVideo(ByVal pbCtrl As PictureBox) hWnd = capCreateCaptureWindowA(FonteVideo, WS_VISIBLE Or WS_CHILD, 0, 0, 0, 0, pbCtrl.Handle.ToInt32, 0) If SendMessage(hWnd, WM_CAP_DRIVER_CONNECT, FonteVideo, 0) Then '---define a escala SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0) '---define a taxa de visualização (ms) SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0) '---inicia visualização da imagem SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0) '---redimensiona a janela para se ajustar ao controle picturebox SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, pbCtrl.Width, pbCtrl.Height, SWP_NOMOVE Or SWP_NOZORDER) Else '--erro ao conectar com o video DestroyWindow(hWnd) End If End Sub Private Sub lstVideoSources_SelectedIndexChanged( _ ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstFontesVideos.SelectedIndexChanged '---para o video se estiver ativo paraJanelaVisualizacao() '---verifica qual fonte de video foi selecionada FonteVideo = lstFontesVideos.SelectedIndex '---visualiza a fonte de video selecionada VisualizaVideo(picImagem) End Sub Private Sub btnParaCamera_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParaCamera.Click paraJanelaVisualizacao() End Sub Private Sub btnIniciaGravacao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIniciaGravacao.Click If lstFontesVideos.SelectedIndex <> -1 Then btnIniciaGravacao.Enabled = False btnParaGravacao.Enabled = True '---inicia a gravação SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0) Else MsgBox("Selecione uma fonte de Vídeo...") End If End Sub Private Sub btnParaGravacao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParaGravacao.Click btnIniciaGravacao.Enabled = True btnParaGravacao.Enabled = False '---salva a gravação para o arquivo na pasta da aplicação SendMessage(hWnd, WM_CAP_FILE_SAVEAS, 0, Application.StartupPath & "\VideoMac.avi") End Sub Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'incluir um novo item paraJanelaVisualizacao() VisualizaVideo(picFoto) End Sub Private Sub btnCapturePhoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapturaFoto.Click 'captura a imagem CapturaImagem() End Sub End Class Compartilhar este post Link para o post Compartilhar em outros sites
diegobill 0 Denunciar post Postado Março 5, 2009 alguem teria o codigo em c++ !? Compartilhar este post Link para o post Compartilhar em outros sites
quintelab 91 Denunciar post Postado Março 6, 2009 Vai ser muito dificil, a maioria aqui domina o c# ou o vb.net. Abraços... Compartilhar este post Link para o post Compartilhar em outros sites
alexandremanowar 0 Denunciar post Postado Março 6, 2009 Boa tarde Esse código que o zeke_ postou é para webforms ou winforms? Compartilhar este post Link para o post Compartilhar em outros sites
Oenning 0 Denunciar post Postado Março 6, 2009 É WinForms. Veja essa linha: Partial Class foto Inherits System.Windows.Forms.Form Compartilhar este post Link para o post Compartilhar em outros sites