ScreenShot erstellen mit MAUI C# Desktop App
2022
Mit Microsoft VisualStudio 2022 und MAUI (früher Xamarin) kann man sehr einfach eine ScreenShot App erstellen.
Allerding kann die Anwendung wie immer nur sich selbst und nicht den Bildschirm aufzeichnen.
Vorschau
namespace MauiApp1;
public partial class MainPage : ContentPage { int count = 0;
public MainPage() { InitializeComponent(); }
private async void OnCounterClicked(object sender, EventArgs e) { var shot = await TakeScreenshotAsync(); img1.Source = shot; }
public async Task<ImageSource> TakeScreenshotAsync() { if (Screenshot.Default.IsCaptureSupported) { IScreenshotResult screen = await Screenshot.Default.CaptureAsync(); Stream stream = await screen.OpenReadAsync(); var x = ImageSource.FromStream(() => stream);
return x; }
return null; } }
|
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MauiApp1.MainPage">
<ScrollView> <VerticalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center">
<Button x:Name="CounterBtn" Text="ScreenShot" SemanticProperties.Hint="Counts the number of times you click" Clicked="OnCounterClicked" HorizontalOptions="Center" />
<Image x:Name="img1" Source=""></Image>
</VerticalStackLayout> </ScrollView>
</ContentPage> |