1

我曾经CaptureSource()在此主题中录制视频,如如何在 Windows Phone 的相机应用程序中录制视频,但我无法获得录制视频的缩略图。

4

2 回答 2

3

这是解决方案:

[...]

// Add eventhandlers for captureSource.
captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed);
captureSource.CaptureImageCompleted += captureSource_CaptureImageCompleted;

[...]

captureSource.Start();
captureSource.CaptureImageAsync();

[...]

void captureSource_CaptureImageCompleted(object sender, CaptureImageCompletedEventArgs e)
{
 using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
  {
    System.Windows.Media.Imaging.WriteableBitmap wb = e.Result;

     string fileName = "CameraMovie.jpg";
     if (isoStore.FileExists(fileName))
         isoStore.DeleteFile(fileName); 

     IsolatedStorageFileStream file = isoStore.CreateFile(fileName);

     System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, file, wb.PixelWidth, wb.PixelHeight, 0, 85);

     file.Close();
 }
}



更新:让用户可以在需要时获取缩略图

将 Tap 事件添加到viewfinderRectangle

<Rectangle 
    x:Name="viewfinderRectangle"
    [...]
    Tap="viewfinderRectangle_Tap" />

调用captureSource.CaptureImageAsync();该 Tap 事件

private void viewfinderRectangle_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
 captureSource.CaptureImageAsync();
}
于 2013-03-09T00:25:49.817 回答
0

你可以试试这个。如果您使用的是 AudioVideoCaptureDevice api。在每帧捕获后调用以下事件。您可以选择任何您需要的框架。作为第一个。

private AudioVideoCaptureDevice VideoRecordingDevice;
VideoRecordingDevice.PreviewFrameAvailable += previewThumbnail;
bool DisablePreviewFrame = false;

private void previewThumbnail(ICameraCaptureDevice a, object b)
{
    if (!DisablePreviewFrame)
    {
        DisablePreviewFrame = true;
        int frameWidth = (int)VideoRecordingDevice.PreviewResolution.Width;
        int frameHeight = (int)VideoRecordingDevice.PreviewResolution.Height;
    }
    int[] buf = new int[frameWidth * frameHeight];
    VideoRecordingDevice.GetPreviewBufferArgb(buf);
    using (IsolatedStorageFile isoStoreFile = IsolatedStorageFile.GetUserStoreForApplication())
    {
        var fileName = "temp.jpg";

        if (isoStoreFile.FileExists(fileName))
            isoStoreFile.DeleteFile(fileName);
        using (IsolatedStorageFileStream isostream = isoStoreFile.CreateFile(fileName))
        {
            WriteableBitmap wb = new WriteableBitmap(frameWidth, frameWidth);
            Array.Copy(buf, wb.Pixels, buf.Length);
            wb.SaveJpeg(isostream, 120, 120, 0, 60);
            isostream.Close();
        }
    }
}
于 2015-06-08T05:05:48.593 回答