【发布时间】:2017-08-03 20:08:18
【问题描述】:
您好,我正在开发一个应用程序,该应用程序允许用户为笔记拍照,然后将它们发送给朋友。我正在使用 xamarin 表单构建此应用程序,并且我还使用媒体插件来访问本机相机,但用户必须按下按钮才能打开本机相机,所以我的问题是如何让相机尽快加载用户打开的应用程序?
这是我的 xaml 代码:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SnapNote.CameraPage"
xmlns:local="clr-namespace:AppName;"
BackgroundColor="{x:Static local:Colors.BackgroundColor}">
<ContentPage.Padding>
<OnPlatform
x:TypeArguments="Thickness"
iOS="10,20,10,10"
Android="10,10,10,10" />
</ContentPage.Padding>
<StackLayout>
<Image Source="TakePhotoButton.png">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="Handle_Clicked" />
</Image.GestureRecognizers>
</Image>
<Image x:Name="image"/>
<Image Source="SendNoteButton.png">
</Image>
</StackLayout>
</ContentPage>
下面是代码:
using System;
using System.Collections.Generic;
using Plugin.Media;
using Plugin.Media.Abstractions;
using Xamarin.Forms;
namespace AppName
{
public partial class CameraPage : ContentPage
{
public CameraPage()
{
InitializeComponent();
}
async void Handle_Clicked(object sender, System.EventArgs e)
{
await CrossMedia.Current.Initialize();
var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
Directory = "MyPhoto",
Name = "Nextflow.jpg",
SaveToAlbum = true
});
if (file == null)
return;
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
}
}
}
任何帮助都会很棒!
提前致谢!
【问题讨论】:
标签: c# xaml xamarin xamarin.forms