首先请在AndroidManiest中添加相机权限:
<uses-permission android:name="android.permission.CAMERA" />
然后,在运行时需要相机权限:
await Permissions.RequestAsync<Permissions.Camera>();
//run the code at app initialization or before you open camera
然后在剃须刀页面:
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private async void IncrementCount()
{
FileResult photo;
if (DeviceInfo.Current.Platform == DevicePlatform.Android || DeviceInfo.Current.Platform == DevicePlatform.iOS)
{
photo = await MediaPicker.CapturePhotoAsync();
}
if (photo == null)
{
return;
}
using (var stream = await photo.OpenReadAsync())
{
var dotnetImageStream = new DotNetStreamReference(stream);
// this is the image stream
// do what you want here
}
}
}