Now i'm trying the first code again. Trying to add the newframe but i get this error:
Error BC30590 Event 'NewFrame' cannot be found.
I've added the AForge.Controls
Here is the code ( scroll down to Private Sub PictureBox1_NewFrame):
Imports AForge.Video
Imports AForge.Video.DirectShow
Imports AForge.Video.FFMPEG
Imports AForge.Controls
Imports System.IO.Ports
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Public Class Form1
Inherits Form
Dim CAMARA As VideoCaptureDevice 'CAMARA QUE ESTAMOS USANDO
Dim BMP As Bitmap 'PARA GENERACION DE IMAGENES
Dim ESCRITOR As New VideoFileWriter() 'GUARDA LAS IMAGENES EN MEMORIA
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom ' POR SI OLVIDAMOS AJUSTAR EL PICTUREBOX
'PORT SETTING BELOW (ADDED BY EFENDY):
Timer1.Interval = 300
Timer1.Enabled = False
datareceive_label.Text = FormStartPosition.CenterParent
Dim available_Ports As Array = IO.Ports.SerialPort.GetPortNames
Dim i As Integer
For i = 0 To UBound(available_Ports)
PortComboBox.Items.Add(available_Ports(i))
Next
BaudrateComboBox.Items.Clear()
BaudrateComboBox.Items.Add("4800")
BaudrateComboBox.Items.Add("9600")
BaudrateComboBox.Items.Add("19200")
BaudrateComboBox.SelectedIndex = 2
ParityComboBox.Items.Clear()
ParityComboBox.Items.Add(IO.Ports.Parity.None)
ParityComboBox.Items.Add(IO.Ports.Parity.Odd)
ParityComboBox.Items.Add(IO.Ports.Parity.Even)
ParityComboBox.SelectedIndex = 2
End Sub
Private Sub ButtonCAMARA_Click(sender As System.Object, e As System.EventArgs) Handles ButtonCAMARA.Click
Dim CAMARAS As VideoCaptureDeviceForm = New VideoCaptureDeviceForm() 'DIALOGO CAMARAS DISPONIBLES
If CAMARAS.ShowDialog() = DialogResult.OK Then
CAMARA = CAMARAS.VideoDevice 'CAMARA ELEGIDA
AddHandler CAMARA.NewFrame, New NewFrameEventHandler(AddressOf CAPTURAR) ' EJECUTARA CADA VEZ QUE SE GENERE UNA IMAGEN
CAMARA.Start() 'INICIA LA PRESENTACION DE IMAGENES EN EL PICTUREBOX
End If
End Sub
Private Sub PictureBox1_NewFrame(sender As Object, ByRef image As Bitmap) Handles PictureBox1.NewFrame
' add overlay
Dim g As Graphics = Graphics.FromImage(image)
g.DrawString(datareceive_label.Text, New Font("courier new", 12), Brushes.Black, New Rectangle(10, 10, 1000, 500))
g.Dispose()
End Sub
Private Sub ButtonVIDEO_Click(sender As System.Object, e As System.EventArgs) Handles ButtonVIDEO.Click
If ButtonVIDEO.BackColor = Color.Black Then 'NO ESTA GRABANDO VIDEO
SaveFileDialog1.DefaultExt = ".avi" ' GUARDARA COMO ARCHIVO AVI
If SaveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim ANCHO As Integer = CAMARA.VideoResolution.FrameSize.Width 'DEFINE EL ANCHO DEL FOTOGRAMA
Dim ALTO As Integer = CAMARA.VideoResolution.FrameSize.Height ' DEFINE EL ALTO DEL FOTOGRAMA
'CREA EL ARCHIVO PARA LOS DATOS CON LOS PARAMETROS DE GUARDADO
ESCRITOR.Open(SaveFileDialog1.FileName, ANCHO, ALTO, NumericUpDownFPS.Value, VideoCodec.Default, NumericUpDownBRT.Value * 1000)
ESCRITOR.WriteVideoFrame(BMP) 'EMPIEZA A GUARDAR DATOS
ButtonVIDEO.BackColor = Color.Red 'PARA QUE SEPAMOS QUE ESTA GRABANDO
End If
Else
ButtonVIDEO.BackColor = Color.Black ' ESTA GRABANDO
ESCRITOR.Close() 'DEJA DE GUARDAR DATOS
End If
End Sub
Private Sub CAPTURAR(sender As Object, eventArgs As NewFrameEventArgs)
If ButtonVIDEO.BackColor = Color.Black Then 'SI NO ESTA GRABANDO ......
BMP = DirectCast(eventArgs.Frame.Clone(), Bitmap) 'PONE LOS DATOS EN EL BITMAP
PictureBox1.Image = DirectCast(eventArgs.Frame.Clone(), Bitmap) 'LOS PRESENTA EN EL PICTURE BOX
Else ' SI ESTAS GRABANDO...
Try
BMP = DirectCast(eventArgs.Frame.Clone(), Bitmap) 'PON LOS DATOS EN EL BITMAP
PictureBox1.Image = DirectCast(eventArgs.Frame.Clone(), Bitmap) 'LOS PRESENTA EN EL PICTURE BOX
ESCRITOR.WriteVideoFrame(BMP) 'LOS GUARDA EN LA MEMORIA
Catch ex As Exception
End Try
End If
End Sub
Private Sub ButtonFOTO_Click(sender As System.Object, e As System.EventArgs) Handles ButtonFOTO.Click
CAPTURA.PictureBox1.Image = PictureBox1.Image 'COPIA LA IMAGEN QUE HAY EN EL PICTUREBOX EN EL PICTUREBOX DEL FORMULARIO CAPTURA
CAPTURA.Show() 'MUESTRA EL FORMULARIO CAPTURA
End Sub
Private Sub ButtonCERRAR_Click(sender As System.Object, e As System.EventArgs) Handles ButtonCERRAR.Click
End
End Sub
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
CAMARA.Stop() 'CIERRA LA CAMARA
ESCRITOR.Close() 'DEJA DE GUARDAR DATOS.
Catch ex As Exception
End Try
End Sub
Private Sub NumericUpDownBRT_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDownBRT.ValueChanged
End Sub
Private Sub Open_btn_Click(sender As Object, e As EventArgs) Handles Open_btn.Click
SerialPort1.PortName = PortComboBox.Text
SerialPort1.BaudRate = BaudrateComboBox.Text
Select Case ParityComboBox.Text
Case "None"
SerialPort1.Parity = IO.Ports.Parity.None
Case "Even"
SerialPort1.Parity = IO.Ports.Parity.Even
Case "Odd"
SerialPort1.Parity = IO.Ports.Parity.Odd
End Select
If SerialPort1.IsOpen Then
SerialPort1.Close()
Timer1.Enabled = False
Open_btn.BackColor = Color.LimeGreen
Else
SerialPort1.Open()
Timer1.Enabled = True
End If
End Sub
Dim Data_received As String
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Data_received &= SerialPort1.ReadExisting
If Len(Data_received) > 0 Then
datareceive_label.Text = Data_received
End If
Data_received = ""
'SEND DATA SETTING ON SERIAL PORT 2
'below are hex codes:
'H10 = CLEAR SCREEN
'H11 = CURSOR RIGHT
'H12 = CURSOR UP
'H13 = CURSOR DOWN
'H14 = CURSOR LEFT
'H15 = HOME CURSOR
'H0A = LINE FEED
'HOD = CARRIAGE RETURN
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
End Class