Skip to content

Commit

Permalink
Update UWP test project
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila committed Nov 15, 2024
1 parent 7f03473 commit 0e589c8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/FrameworkTests/MauiApp/MauiApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.0" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.10" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
38 changes: 22 additions & 16 deletions src/FrameworkTests/Uwp/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
<Page x:Class="PDFtoImage.FrameworkTests.Uwp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PDFtoImage.FrameworkTests.Uwp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:PDFtoImage.FrameworkTests.Uwp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<Grid>
<StackPanel Padding="30,0"
Spacing="25"
Orientation="Vertical"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<TextBlock FontSize="32"
HorizontalAlignment="Center"
Text="Hello, World!"/>
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical"
Spacing="25">
<Image x:Name="imgTest"
MaxHeight="200"
MaxWidth="200"
HorizontalAlignment="Center"
Source="dotnet_bot.png"
Stretch="Fill" />
<TextBlock HorizontalAlignment="Center"
FontSize="32"
Text="Hello, World!" />
<TextBlock x:Name="OutputLabel"
FontSize="18"
HorizontalAlignment="Center"
HorizontalAlignment="Center"
FontSize="18"
IsTextSelectionEnabled="True"
Text="Tab the button below to test PDFtoImage."/>
Text="Tab the button below to test PDFtoImage." />
<Button x:Name="CounterBtn"
Click="CounterBtn_Click"
HorizontalAlignment="Center"
Content="Click me"/>
HorizontalAlignment="Center"
Click="CounterBtn_Click"
Content="Click me" />
</StackPanel>
</Grid>
</Page>
26 changes: 23 additions & 3 deletions src/FrameworkTests/Uwp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using SkiaSharp;
using System;
using System.IO;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;

namespace PDFtoImage.FrameworkTests.Uwp
{
Expand All @@ -11,15 +14,32 @@ public MainPage()
InitializeComponent();
}

private void CounterBtn_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
private async void CounterBtn_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
try
{
using (var input = new FileStream("SocialPreview.pdf", FileMode.Open, FileAccess.Read))
{
using (var bitmap = PDFtoImage.Conversion.ToImage(input))
{
OutputLabel.Text = $"SocialPreview.pdf size: {bitmap.Width}x{bitmap.Height}";
using (var encodedImage = new MemoryStream())
{
OutputLabel.Text = $"SocialPreview.pdf size: {bitmap.Width}x{bitmap.Height}";
bitmap.Encode(encodedImage, SKEncodedImageFormat.Png, 100);

var byteArray = encodedImage.ToArray();

var bitmapImage = new BitmapImage
{
DecodePixelHeight = bitmap.Width,
DecodePixelWidth = bitmap.Height
};

encodedImage.Seek(0, SeekOrigin.Begin);
await bitmapImage.SetSourceAsync(encodedImage.AsRandomAccessStream());

imgTest.Source = bitmapImage;
}
}
}
}
Expand Down

0 comments on commit 0e589c8

Please sign in to comment.