December 2019
Intermediate to advanced
528 pages
11h 19m
English
Now that we've added the plugin, we can create the code so that we can use the camera. Let's have a quick look at this method:
private async Task<MediaFile> TakePicture() { string fileName = $"FaceImg_{DateTime.Now.Ticks}"; MediaFile photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions() { SaveToAlbum = true, Name = fileName }); if (photo != null) { return photo; } return null; }
There's not much to this method since the plugin does the bulk of the work for us. The parameters that we're passing in allow the image to be saved, and we're declaring a unique name for it.