要做到这一点有 2 个部分。您需要打开一个相机活动:
关于这个有多个tutorials:
安卓
App.Instance.ShouldTakePicture += () => {
var intent = new Intent(MediaStore.ActionImageCapture);
intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(file));
StartActivityForResult(intent, 0);
};
IOS
imagePicker.FinishedPickingMedia += (sender, e) => {
var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "tmp.png");
var image = (UIImage)e.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
InvokeOnMainThread(() => {
image.AsPNG().Save(filepath, false);
App.Instance.ShowImage(filepath);
});
DismissViewController(true, null);
};
下一步是使用facial recognition,一旦你有了用户的脸,你就可以存储图像了。
using (var stream = photo.GetStream())
{
var faceServiceClient = new FaceServiceClient("{FACE_API_SUBSCRIPTION_KEY}");
// Step 4a - Detect the faces in this photo.
var faces = await faceServiceClient.DetectAsync(stream);
var faceIds = faces.Select(face => face.FaceId).ToArray();
// Step 4b - Identify the person in the photo, based on the face.
var results = await faceServiceClient.IdentifyAsync(personGroupId, faceIds);
var result = results[0].Candidates[0].PersonId;
// Step 4c - Fetch the person from the PersonId and display their name.
var person = await faceServiceClient.GetPersonAsync(personGroupId, result);
UserDialogs.Instance.ShowSuccess($"Person identified is {person.Name}.");
}