使用 C# (AForge) 拍摄快照
take snapshot with c# (AForge)
我用 AForge 做了这个代码。输出应该是用 Wabcam 拍摄的照片(保存在 "C:\users\me\Desktop\Picture.jpg" 中)。
守则只是不这样做,我不知道为什么。谢谢
static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
bitmap.Save(@"c:\users\me\desktop\picture.jpg");
}
static void Main(string[] args)
{
FilterInfoCollection videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice ); VideoCaptureDevice videoSource = new VideoCaptureDevice( videoDevices[0].MonikerString );
videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
videoSource.Start();
videoSource.SignalToStop();
}
试试这个:
public static bool x = false;
static void Main(string[] args)
{
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
videoSource.Start();
while (true)
{
if (x == true)
{
videoSource.SignalToStop();
break;
}
}
}
static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
bitmap.Save(@"C:\Users\Skydr\Desktop\C++_Project\a.jpg");
x = true;
}
谢谢 Adola 我这样解决了问题 :
static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame;
bitmap.Save(@"c:\users\me\desktop\picture.jpg");
static void Main(string[] args)
{
bool finish = false ;
FilterInfoCollection videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice );
VideoCaptureDevice videoSource = new VideoCaptureDevice( videoDevices[0].MonikerString );
videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
videoSource.Start();
do{
if (File.Exists(@"c:\users\me\desktop\picture.jpg"))
{
finish = true;
videoSource.SignalToStop();
}
} while (finish != true);
}
我用 AForge 做了这个代码。输出应该是用 Wabcam 拍摄的照片(保存在 "C:\users\me\Desktop\Picture.jpg" 中)。 守则只是不这样做,我不知道为什么。谢谢
static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
bitmap.Save(@"c:\users\me\desktop\picture.jpg");
}
static void Main(string[] args)
{
FilterInfoCollection videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice ); VideoCaptureDevice videoSource = new VideoCaptureDevice( videoDevices[0].MonikerString );
videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
videoSource.Start();
videoSource.SignalToStop();
}
试试这个:
public static bool x = false;
static void Main(string[] args)
{
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
videoSource.Start();
while (true)
{
if (x == true)
{
videoSource.SignalToStop();
break;
}
}
}
static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
bitmap.Save(@"C:\Users\Skydr\Desktop\C++_Project\a.jpg");
x = true;
}
谢谢 Adola 我这样解决了问题 :
static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame;
bitmap.Save(@"c:\users\me\desktop\picture.jpg");
static void Main(string[] args)
{
bool finish = false ;
FilterInfoCollection videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice );
VideoCaptureDevice videoSource = new VideoCaptureDevice( videoDevices[0].MonikerString );
videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
videoSource.Start();
do{
if (File.Exists(@"c:\users\me\desktop\picture.jpg"))
{
finish = true;
videoSource.SignalToStop();
}
} while (finish != true);
}