Gregory
Gregory

Reputation: 159

Maui XAML 'ImageSource.FromStream' remains null?

Bit new to Maui, trying to update an ImageSource at runtime. I've been searching for quite a few hours now. Any help is welcome. The code runs without any errors, yet the 'Source' of the Image object remains 'null' (stream is ok)

eventArgs.Frame => System.Drawing.Bitmap

camcap => <Image x:Name="camcap"/>

using (MemoryStream stream = new MemoryStream())
            {
                eventArgs.Frame.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                MainThread.BeginInvokeOnMainThread(() => this.camcap.Source = ImageSource.FromStream(() => stream));
            }

Upvotes: 0

Views: 224

Answers (1)

Guangyu Bai - MSFT
Guangyu Bai - MSFT

Reputation: 4586

You can use the OnAppearing() method to update an ImageSource at runtime. Here is the document about the OnAppearing() method you can refer to.

   protected override void OnAppearing()
    {
        base.OnAppearing();
    
        Stream stream = new MemoryStream();
        eventArgs.Frame.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        camcap.Source = ImageSource.FromStream(() => { return stream; });
    
       
    }

Upvotes: 1

Related Questions