Screenshots, as the name implies, are photos that are taken of the screen of our device and allow us to capture exactly the scenario that we want in an application. In this case, we will learn how to implement that in our .NET MAUI applications in a super easy way!
To take Screenshots .NET MAUI gives us the
ISscreenshot interface which is exposed through the
Screenshot.Default property which is available in the
📸 Capturing the screenshot
There is a property that helps us confirm that our device supports this functionality:
🔹 IsCaptureSupported: Returns a bool value – Gets a value indicating whether the capturing screenshots are supported.
But also, we have the method that has the most responsibility for making all of this happen:
🔹 CaptureAsync: Returns an
ISscreenshotResult. – It’s responsible for capturing the screenshot of the current application. As a result, we have access to different informations about this one, such as width and height.
IScreenshotResult also has a
Stream property that is used to convert the screenshot to an image object.
Joining all the points explained above, we would finally have an example of a method that takes a Screenshot and returns it as an
ImageSource, let’s see it in the following code block:
⚠ Example extracted from the official documentation.
Not all views support screen-level capture, such as an OpenGL view.
I hope this article has been helpful to you! 🙋♀️
See you next time!💚💕