Get Picture from webcam

Jan 26, 2012 at 3:38 PM

Hi everybody,

can i create an button, to make pics from the webcam.

I use the VideoCaptureElement, which works perfect.

The next step for me is, to make pictures with the cam, when i press a button.
Wich event can i use?

Has anybody an idea?



Jan 31, 2012 at 10:42 AM

I found a solution, to get Pictures from the webcam.

The last problem is only the picutre size. The most part of the picture is black - Can anyone tell me what is the reason

Her is my code.



                DesiredPixelWidth="1280" DesiredPixelHeight="720"LoadedBehavior="Play" EnableSampleGrabbing="true"
                FPS="30" Width="Auto" Height="Auto" x:Name="videoCapElement" 
VideoCaptureDevice="{Binding SelectedItem, ElementName=videoCapDevices}" VideoCaptureSource="{Binding CaptureDeviceName}"/>
<ComboBox x:Name="videoCapDevices" ItemsSource="{Binding Source={x:Static WPFMediaKit:MultimediaUtil.VideoInputDevices}}" DisplayMemberPath="Name" Foreground="Black"/> <Label Content="{Binding VideoCaptureDevice, ElementName=videoCapElement}" />


private void imgMakePic_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
RenderTargetBitmap bmp = new RenderTargetBitmap(Properties.Settings.Default.Height, Properties.Settings.Default.Width, 96, 96, PixelFormats.Pbgra32); bmp.Render(videoCapElement); BitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bmp)); string now = DateTime.Now.Year + "" + DateTime.Now.Month + "" + DateTime.Now.Day + "" + DateTime.Now.Hour + "" + DateTime.Now.Minute + "" + DateTime.Now.Second; string filename = "D:\\" + now + "pic.jpg"; FileStream fstream = new FileStream(filename, FileMode.Create); encoder.Save(fstream); fstream.Close(); }
Apr 11, 2012 at 11:15 AM


first, you have to switch the height and width

RenderTargetBitmap bmp = new RenderTargetBitmap(Properties.Settings.Default.Width, Properties.Settings.Default.Height, 96, 96, PixelFormats.Pbgra32);

then you have to use another PixelFormat. I have used the Default and it worked fine.

RenderTargetBitmap bmp = new RenderTargetBitmap(Properties.Settings.Default.Width, Properties.Settings.Default.Height, 96, 96, PixelFormats.Default);


Greeting BPuls