-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 Add basic image selection UI for the image library.
No backend service yet. This is intended to manage the image library imported in the backend.
- Loading branch information
Showing
6 changed files
with
215 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Exo/Ui/Exo.Settings.Ui/Converters/ByteArrayToBitmapImageConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Media.Imaging; | ||
|
||
namespace Exo.Settings.Ui.Converters; | ||
|
||
internal sealed class ByteArrayToBitmapImageConverter : IValueConverter | ||
{ | ||
public object? Convert(object value, Type targetType, object parameter, string language) | ||
{ | ||
if (value is not byte[] data) return null; | ||
|
||
var bitmapImage = new BitmapImage(); | ||
LoadImage(bitmapImage, data); | ||
return bitmapImage; | ||
} | ||
|
||
private async void LoadImage(BitmapImage bitmapImage, byte[] data) | ||
{ | ||
try | ||
{ | ||
using (var memoryStream = new MemoryStream(data, 0, data.Length, true, true)) | ||
using (var randomAccessStream = memoryStream.AsRandomAccessStream()) | ||
{ | ||
await bitmapImage.SetSourceAsync(randomAccessStream); | ||
} | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException(); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Exo/Ui/Exo.Settings.Ui/Converters/FileNameToBitmapImageConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Media.Imaging; | ||
using Windows.Storage.Streams; | ||
|
||
namespace Exo.Settings.Ui.Converters; | ||
|
||
internal sealed class FileNameToBitmapImageConverter : IValueConverter | ||
{ | ||
public object? Convert(object value, Type targetType, object parameter, string language) | ||
{ | ||
if (value is not string fileName) return null; | ||
|
||
var bitmapImage = new BitmapImage(); | ||
LoadImage(bitmapImage, fileName); | ||
return bitmapImage; | ||
} | ||
|
||
private async void LoadImage(BitmapImage bitmapImage, string fileName) | ||
{ | ||
try | ||
{ | ||
using (var randomAccessStream = await FileRandomAccessStream.OpenAsync(fileName, Windows.Storage.FileAccessMode.Read, Windows.Storage.StorageOpenOptions.AllowOnlyReaders, FileOpenDisposition.OpenExisting)) | ||
{ | ||
await bitmapImage.SetSourceAsync(randomAccessStream); | ||
} | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters