I've used CaptureSource()
to record a video like in this Topic How to record video in a camera app for Windows Phone, but I can't get the thumbnail of the recorded video.
Asked
Active
Viewed 1,960 times
1

Ouadie
- 13,005
- 4
- 52
- 62
2 Answers
3
Here is the solution:
[...]
// 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 : Give the user the possibility to take the thumbnail when he want
Add an Tap event to viewfinderRectangle
<Rectangle
x:Name="viewfinderRectangle"
[...]
Tap="viewfinderRectangle_Tap" />
Call captureSource.CaptureImageAsync();
in that Tap event
private void viewfinderRectangle_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
captureSource.CaptureImageAsync();
}

Ouadie
- 13,005
- 4
- 52
- 62
-
how to get the size of the video while recording is on? – Milan Aggarwal Jul 18 '13 at 06:26
-
I don't know if it's possible to get the size of the video while recording – Ouadie Jul 18 '13 at 08:01
-
any ide aon how to change the resolution? http://stackoverflow.com/questions/17715390/how-to-change-the-resolution-of-camera-while-recording-video-in-wp8 – Milan Aggarwal Jul 18 '13 at 08:33
-
Have you seen this : http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662939(v=vs.105).aspx – Ouadie Jul 18 '13 at 13:58
-
I am using AudioVideoCaptureDevice. is there any way to get the thumbnail from this – pranavjayadev Aug 07 '13 at 11:00
0
You can try this. If you are using AudioVideoCaptureDevice api. following events call after every frame capture. You can choose any frame that you need. As take first one.
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();
}
}
}

reza.cse08
- 5,938
- 48
- 39