Skip to content

Commit d7c727a

Browse files
committed
release: Improve image loading & quality.
1 parent a0cc947 commit d7c727a

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/Flarial.Launcher/Controls/PromotionImageButton.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ protected PromotionImageButton() : base(new())
2323
{
2424
(~this).Width = 320 * 0.95;
2525
(~this).Height = 50 * 0.95;
26-
(~this).Visibility = Visibility.Collapsed;
2726

2827
(~this).Tag = NavigateUri;
29-
(~this).ImageFailed += OnImageFailed;
28+
(~this).Visibility = Visibility.Collapsed;
29+
30+
(~this).Source = new BitmapImage
31+
{
32+
DecodePixelWidth = (int)(~this).Width,
33+
DecodePixelHeight = (int)(~this).Height,
34+
DecodePixelType = DecodePixelType.Logical,
35+
UriSource = ImageUri is { } ? new(ImageUri) : null,
36+
};
37+
38+
(~this).ImageOpened += OnImageOpened;
3039
(~this).PointerExited += OnImagePointerExited;
3140
(~this).PointerEntered += OnImagePointerEntered;
3241
(~this).PointerPressed += OnImagePointerPressed;
33-
34-
if (ImageUri is { })
35-
{
36-
(~this).Visibility = Visibility.Visible;
37-
(~this).Source = new BitmapImage { UriSource = new(ImageUri) };
38-
}
3942
}
4043

4144
unsafe static void OnImagePointerPressed(object sender, RoutedEventArgs args)
@@ -44,7 +47,7 @@ unsafe static void OnImagePointerPressed(object sender, RoutedEventArgs args)
4447
ShellExecute(Null, null, lpFile, null, null, SW_NORMAL);
4548
}
4649

47-
static void OnImageFailed(object sender, RoutedEventArgs args) => ((Image)sender).Visibility = Visibility.Collapsed;
50+
static void OnImageOpened(object sender, RoutedEventArgs args) => ((Image)sender).Visibility = Visibility.Visible;
4851
static void OnImagePointerEntered(object sender, RoutedEventArgs args) => CoreWindow.GetForCurrentThread().PointerCursor = _hand;
4952
static void OnImagePointerExited(object sender, RoutedEventArgs args) => CoreWindow.GetForCurrentThread().PointerCursor = _arrow;
5053
}

src/Flarial.Launcher/Pages/HomePage.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Flarial.Launcher.Pages;
1717

1818
sealed class HomePage : Grid
1919
{
20-
readonly Image _logoImage = new()
20+
readonly Image _image = new()
2121
{
2222
Width = 96,
2323
Height = 96,
@@ -76,15 +76,15 @@ internal HomePage(MainNavigationView view, ApplicationSettings settings)
7676

7777
using (var stream = ApplicationManifest.GetResourceStream("Application.ico"))
7878
{
79-
var logoBitmap = (BitmapImage)_logoImage.Source;
80-
logoBitmap.SetSource(stream.AsRandomAccessStream());
79+
var source = (BitmapImage)_image.Source;
80+
source.SetSource(stream.AsRandomAccessStream());
8181
}
8282

8383
Children.Add(_leftText);
8484
Children.Add(_rightText);
8585

8686
Children.Add(_button);
87-
Children.Add(_logoImage);
87+
Children.Add(_image);
8888

8989
Children.Add(new PromotionImagesBox()
9090
{
@@ -95,10 +95,7 @@ internal HomePage(MainNavigationView view, ApplicationSettings settings)
9595
_button.Click += OnButtonClick;
9696
}
9797

98-
void OnFlarialClientDownloadAsync(int value) => Dispatcher.Invoke(() =>
99-
{
100-
_button.Content = $"Downloading... {value}%";
101-
});
98+
void OnFlarialClientDownloadAsync(int value) => Dispatcher.Invoke(() => _button.Content = $"Downloading... {value}%");
10299

103100
async void OnButtonClick(object sender, RoutedEventArgs args)
104101
{

0 commit comments

Comments
 (0)