:: AForge.NET Framework :: Articles :: Forums ::

exception cast Aforge

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

exception cast Aforge

Postby yosri » Tue Apr 25, 2017 10:58 pm

hi all , im trying to capture images through my webcam and save them in a folder using Aforge,
it runs an exeption , can not cast system.eventargs to Aforge.videonewframeeventargs any help

my code is :

Imports AForge
Imports AForge.Video
Imports AForge.Video.DirectShow
Imports System.IO

Public Class Form1
Dim CAMERA As VideoCaptureDevice
Dim bmp As Bitmap
Dim e As EventArgs

Public Sub Captured(sender As Object, EventArgs As NewFrameEventArgs)
bmp = DirectCast(EventArgs.Frame.Clone(), Bitmap)
PictureBox1.Image = DirectCast(EventArgs.Frame.Clone(), Bitmap)
End Sub
'Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' End Sub
'Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button2.Click
' SaveFileDialog1.DefaultExt = ".jpg"
'If SaveFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
' PictureBox2.Image.Save(SaveFileDialog1.FileName, Imaging.ImageFormat.Jpeg)
'End If
'End Sub

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Me.Timer1.Interval = 2000
Dim cameras As VideoCaptureDeviceForm = New VideoCaptureDeviceForm
If cameras.ShowDialog = System.Windows.Forms.DialogResult.OK Then
CAMERA = cameras.VideoDevice
AddHandler CAMERA.NewFrame, New NewFrameEventHandler(AddressOf Captured)
End If
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

Captured(sender, e)

'bmp = DirectCast(EventArgs.Frame.Clone(), Bitmap)
'PictureBox1.Image = DirectCast(EventArgs.Frame.Clone(), Bitmap)
PictureBox2.Image = PictureBox1.Image

' SaveFileDialog1.DefaultExt = ".jpg"
'If SaveFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
'PictureBox2.Image.Save(SaveFileDialog1.FileName, Imaging.ImageFormat.Jpeg)
PictureBox1.Image.Save("C:\Users\Karl\Desktop\Screenshot\filename.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
Catch ex As Exception
End Try
' End If
End Sub
End Class
Posts: 1
Joined: Mon Apr 24, 2017 4:16 pm

Return to AForge.NET Framework