2013-03-07 65 views

回答

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(); 
} 
} 



UPDATE:給用戶的可能性時,他想

在點擊事件的點擊事件viewfinderRectangle

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

呼叫captureSource.CaptureImageAsync();添加拿縮略圖

private void viewfinderRectangle_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
{ 
captureSource.CaptureImageAsync(); 
} 
+0

如何獲取視頻的大小,同時記錄是? – 2013-07-18 06:26:05

+0

我不知道是否有可能在錄製時獲得視頻的大小 – Ouadie 2013-07-18 08:01:57

+0

任何想法如何更改分辨率? http://stackoverflow.com/questions/17715390/how-to-change-the-resolution-of-camera-while-recording-video-in-wp8 – 2013-07-18 08:33:20

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(); 
     } 
    } 
}