我有一个使用相机拍摄图像的项目。
捕获图像后,它将显示在我的视图中。
我需要做的是在我的视图中获取附加图像并将其转换为Base64。
我的观点:
<StackLayout Orientation="Horizontal">
<Label x:Name="CaptureLabel" Text="Capture Image:" TextColor="Black" FontSize="12" Margin="20,10,0,0"
VerticalOptions="StartAndExpand" HorizontalOptions="Start"></Label>
<Image x:Name="CameraButton" Margin="20,5,15,0" HorizontalOptions="EndAndExpand">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Image.GestureRecognizers>
</Image>
</StackLayout>
我的守则背后:
private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
var photo = await Media.Plugin.CrossMedia.Current.TakePhotoAsync(new Media.Plugin.Abstractions.StoreCameraMediaOptions() { });
if (photo != null)
CameraButton.Source = ImageSource.FromStream(() => { return photo.GetStream(); });
CameraButton.HeightRequest = 80;
CameraButton.WidthRequest = 50;
MainStack.HeightRequest = 470;
}