如何获取录制视频的缩略图 - Windows Phone 8?
问题描述:
我用CaptureSource()
来录制像这个主题How to record video in a camera app for Windows Phone一样的视频,但我无法获得录制视频的缩略图。如何获取录制视频的缩略图 - Windows Phone 8?
答
下面是解:
[...]
// 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();
}
}
UPDATE:给用户的可能性时,他想
在点击事件的点击事件viewfinderRectangle
<Rectangle
x:Name="viewfinderRectangle"
[...]
Tap="viewfinderRectangle_Tap" />
呼叫captureSource.CaptureImageAsync();
添加拿缩略图
private void viewfinderRectangle_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
captureSource.CaptureImageAsync();
}
答
你可以试试这个。如果您使用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();
}
}
}
如何获取视频的大小,同时记录是? – 2013-07-18 06:26:05
我不知道是否有可能在录制时获得视频的大小 – Ouadie 2013-07-18 08:01:57
任何想法如何更改分辨率? http://stackoverflow.com/questions/17715390/how-to-change-the-resolution-of-camera-while-recording-video-in-wp8 – 2013-07-18 08:33:20