Getting Full Resolution Photos

Apr 12, 2012 at 11:52 PM
Edited Apr 12, 2012 at 11:55 PM

I am trying to get photos from a webcam using the following code:

<WPFMediaKit:VideoCaptureElement DesiredPixelWidth="1600"
                                 DesiredPixelHeight="1200"
                                 LoadedBehavior="Play"
                                 EnableSampleGrabbing="true"
                                 FPS="30"
                                 Width="240"
                                 Height="180"
                                 HorizontalAlignment="Left"
                                 x:Name="videoCapElement"
                                 VideoCaptureDevice="{Binding Path=SelectedCamera}"
                                 VideoCaptureSource="{Binding Path=SelectedCamera.Name}">
    <WPFMediaKit:VideoCaptureElement.LayoutTransform>
        <RotateTransform CenterX="0.5"
                         CenterY="0.5"
                         Angle="90" />
    </WPFMediaKit:VideoCaptureElement.LayoutTransform>
</WPFMediaKit:VideoCaptureElement>
private void Image_Click(object sender, RoutedEventArgs e)
{
    RenderTargetBitmap bmp = new RenderTargetBitmap(1200, 1600, 300, 300, PixelFormats.Default);
    bmp.Render(videoCapElement);
    BitmapEncoder encoder = new JpegBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(bmp));

    Directory.CreateDirectory("C:\\Photos\\");
    string filename = "C:\\Photos\\" + "test.jpg";
    FileStream fstream = new FileStream(filename, FileMode.Create);
    encoder.Save(fstream);
    fstream.Close();
}

I am only getting 180x240 pictures with rest being black. Is there any way that I can have the live "viewfinder" image be smaller and the actual saved photograph file be much larger?


I tried constructing a second, larger, VideoCaptureElement in code and using that one for the bitmap but all I got was a black image on that one.

May 3, 2012 at 8:44 PM

Did you find a solution to this?
I'm running into the same issue.

Jun 6, 2012 at 9:28 AM

me too, same issue

Jun 6, 2012 at 10:03 AM

It would be nice to know why its doing it but a work around I've found is to use a cropped bitmap....

 

        Dim bmp = New RenderTargetBitmap(2560, 1440, 150, 150, PixelFormats.Default)
        bmp.Render(vce)

        Dim cb As New CroppedBitmap(bmp, New Int32Rect(248, 178, 1508, 845))
        'select region rect

        Dim encoder = New JpegBitmapEncoder()
        encoder.Frames.Add(BitmapFrame.Create(cb))

        Dim filename = "C:\Photos\" + "test.jpg"
        Dim fstream = New FileStream(filename, FileMode.Create)
        encoder.Save(fstream)
        fstream.Close()

Jun 7, 2012 at 5:04 PM

Actually this issue is sorted by putting the VCE inside a canvas

Jun 7, 2012 at 5:31 PM

Are you having an issue with image quality? The app I am working on is for use with this Win7 tablet. The tablet comes with a "camera" app for snapping stills. It has a live viewfinder and it takes stills at the max res of the camera. However, the stills from the built-in app are of much higher quality than what my app is producing... Same resolution but much clearer, it makes me wonder how they are doing it.