我已使用CaptureSource()
来录制此主题How to record video in a camera app for Windows Phone中的视频,但我无法获取录制视频的缩略图。
答案 0 :(得分: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();
}
}
更新:让用户可以在需要时获取缩略图
将点击事件添加到viewfinderRectangle
<Rectangle
x:Name="viewfinderRectangle"
[...]
Tap="viewfinderRectangle_Tap" />
在该点击事件中调用captureSource.CaptureImageAsync();
private void viewfinderRectangle_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
captureSource.CaptureImageAsync();
}
答案 1 :(得分: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();
}
}
}