So, i saw many examples here and i am trying to adapt to my code ! But, when appears the image, comes blank... i am a newbie, so... lol
I just want to show the image after click on the button !! Is not to save on the smartphone.
The .cs code:
ApiCall apiCallFoto = new ApiCall(); ImageSource imagem = null; btnFoto.Clicked += async (sender, e) => { await apiCallFoto.GetFoto<byte[]>("Nomes", "Foto", envolvID).ContinueWith(t => { //Aqui verificamos se houve problema ne requisição if (t.IsFaulted) { Debug.WriteLine(t.Exception.Message); Device.BeginInvokeOnMainThread(() => { DisplayAlert("Falha", "Ocorreu um erro na Requisição :(", "Ok"); }); } //Aqui verificamos se a requisição foi cancelada por algum Motivo else if (t.IsCanceled) { Debug.WriteLine("Requisição cancelada"); Device.BeginInvokeOnMainThread(() => { DisplayAlert("Cancela", "Requisição Cancelada :O", "Ok"); }); } //Caso a requisição ocorra sem problemas, cairemos aqui else { //Se Chegarmos aqui, está tudo ok, agora itemos tratar nossa Lista Device.BeginInvokeOnMainThread(() => { byte[] fotoBytes = t.Result; // Image image = new Image(); imagem = ImageSource.FromStream(() => new MemoryStream(fotoBytes)); Navigation.PushAsync(new FotoEnvolvido(imagem)); }); } }); };
The FotoEnvolvido.cs :
public partial class FotoEnvolvido : ContentPage { private ImageSource imagem; public FotoEnvolvido(ImageSource imagem) { InitializeComponent(); this.imagem = imagem; BindingContext = imagem; } }
The FotoEnvolvido.xaml :
<Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="100"/> </Grid.RowDefinitions> <Image Source="{Binding imagem}" x:Name="fotoperfil"/> </Grid>