CameraCaptureUI capture = new CameraCaptureUI();
capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
capture.PhotoSettings.CroppedAspectRatio = new Size(1, 2);
capture.PhotoSettings.MaxResolution=CameraCaptureUIMaxPhotoResolution.HighestAvailable
StorageFile storeFile=await capture.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (storeFile != null)
{
var stream = await storeFile.OpenAsync(FileAccessMode.Read);
BitmapImage bimage = new BitmapImage();
bimage.SetSource(stream);
Image imageitem = new Image();
imageitem.Source = bimage;
my_canvas.Children.Add(imageitem);
Asked
Active
Viewed 384 times
-1

Sayse
- 42,633
- 14
- 77
- 146

vikas sharawat
- 217
- 1
- 13
-
You should describe your problem a little more in detail. Also comments inside your code would help to understand it better and faster. (What is this part of code supposed to do, why is it there) Otherwise people will downvote your question, or even close it as off topic. – Mong Zhu Jun 09 '16 at 06:49
2 Answers
1
You can also use MediaCapture to record video, this an extract from a project I've worked on (some of this I wrote just now from memory, I'll correct this if need be when I get home):
public class CameraController
{
private MediaCapture _mediaCap;
private bool _isInitialised;
public async Task InitialiseWebCam()
{
if (!_isInitialised)
{
var settings = ApplicationData.Current.LocalSettings;
string preferredDeviceName = $"{settings.Values["PreferredDeviceName"]}";
var videoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
DeviceInformation device = videoDevices.FirstOrDefault(x => x.Name == preferredDeviceName);
if (device == null)
device = videoDevices.FirstOrDefault();
if (device == null)
throw new Exception("Cannot find a camera device");
else
{
//initialize the WebCam via MediaCapture object
_mediaCap = new MediaCapture();
var initSettings = new MediaCaptureInitializationSettings { VideoDeviceId = device.Id };
await _mediaCap.InitializeAsync(initSettings);
_mediaCap.Failed += new MediaCaptureFailedEventHandler(MediaCaptureFailed);
_isInitialised = true;
}
}
}
public async StorageFile RecordVideo(TimeSpan duration)
{
if (!_isInitialised)
await InitialiseWebCam();
StorageFile videoFile = await KnownFolders.VideosLibrary.CreateFileAsync(
$"video_{DateTime.Now.ToString("yyyyMMddHHmmss")}.mp4", CreationCollisionOption.GenerateUniqueName);
var mediaEncoding = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
await _mediaCap.StartRecordToStorageFileAsync(mediaEncoding, videoFile);
await Task.Delay(duration);
await _mediaCap.StopRecordAsync();
return videoFile;
}
private void MediaCaptureFailed(MediaCapture sender, MediaCaptureFailedEventArgs errorEventArgs)
{
//TODO: Implement this
}
}

Detail
- 785
- 9
- 23
0
Just use standard sample for recording video from Capture photos and video with CameraCaptureUI
CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;
StorageFile videoFile = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Video);
if (videoFile == null)
{
// User cancelled photo capture
return;
}

Alexej Sommer
- 2,677
- 1
- 14
- 25