Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo de utilização da Câmera - Xamarin.Forms http://julianocustodio.com/2017/08/31/camera-xamarin-forms
using Plugin.Media;
using Plugin.Media.Abstractions;
using System;
using Xamarin.Forms;
namespace DemoCamera
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void TirarFoto(object sender, EventArgs e)
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsTakePhotoSupported || !CrossMedia.Current.IsCameraAvailable)
{
await DisplayAlert("Ops" , "Nenhuma câmera detectada.", "OK");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(
new StoreCameraMediaOptions
{
SaveToAlbum = true,
Directory = "Demo"
});
if (file == null)
return;
MinhaImagem.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
}
private async void EscolherFoto(object sender, EventArgs e)
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsPickPhotoSupported)
{
await DisplayAlert("Ops", "Galeria de fotos não suportada.", "OK");
return;
}
var file = await CrossMedia.Current.PickPhotoAsync();
if (file == null)
return;
MinhaImagem.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
}
private async void GravarVideo(object sender, EventArgs e)
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsTakeVideoSupported || !CrossMedia.Current.IsCameraAvailable)
{
await DisplayAlert("Ops", "Nenhuma câmera detectada.", "OK");
return;
}
var file = await CrossMedia.Current.TakeVideoAsync(
new StoreVideoOptions
{
SaveToAlbum = true,
Directory = "Demo",
Quality = VideoQuality.Medium
});
if (file == null)
return;
MinhaImagem.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
}
private async void EscolherVideo(object sender, EventArgs e)
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsPickVideoSupported)
{
await DisplayAlert("Ops", "Galeria de videos não suportada.", "OK");
return;
}
var file = await CrossMedia.Current.PickVideoAsync();
if (file == null)
return;
MinhaImagem.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.