Monday, 25 January 2021

Take Partial Screenshots of Your Xamarin.Forms App - Extension methods for capturing images from UI

 

Extension methods for capturing images from UI . 

Nuget Required : 

https://www.nuget.org/packages/ImageFromXamarinUI/1.0.0-pre1 [install in all three projects]

This is how you can create a simple command to call CaptureImageAsync method




JUST CLICK ON CAPTURE IT WILL SHOW YOUR STACK LAYOUT OR SELECTED CONTROL
IN IMAGE VIEW.


public ImageSource ResultImageSource { get; set; }

public ICommand CaptureCommand  => new Command<Xamarin.Forms.VisualElement>(OnCapture);

async void OnCapture(Xamarin.Forms.VisualElement element)
{
    try
    {
        var stream = await element.CaptureImageAsync();
        ResultImageSource = ImageSource.FromStream(() => stream);
    }
    catch (Exception)
    {
        // Handle exception that share failed
    }        
}

You can pass in the calling element when the Command is triggered:

<StackLayout x:Name="rootView">
   <Button Text="Capture"
           Command="{Binding CaptureCommand}"
           CommandParameter="{x:Reference rootView}"/>
</StackLayout>
GITHUB LINK



2 comments:

  1. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site. For more info:- Xamarin App Development

    ReplyDelete
  2. Helping readers by your ideas is really apprecitable. Keep updating us through your upcoming more articles. Hope to get more content soon. Now it's time to avail earbuds for more information.

    ReplyDelete

All About .NET MAUI

  What’s .NET MAUI? .NET MAUI (.NET Multi-platform App UI) is a framework for building modern, multi-platform, natively compiled iOS, Androi...

Ads2