2017-10-27 17:15:18 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2022-01-14 20:22:56 +01:00
|
|
|
|
// © 2022 Clemens Fischer
|
2017-10-27 17:15:18 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Windows.Storage;
|
|
|
|
|
|
using Windows.Storage.Streams;
|
2021-06-14 21:41:37 +02:00
|
|
|
|
#if WINUI
|
|
|
|
|
|
using Microsoft.UI.Xaml.Media;
|
|
|
|
|
|
using Microsoft.UI.Xaml.Media.Imaging;
|
|
|
|
|
|
#else
|
2019-06-13 21:38:01 +02:00
|
|
|
|
using Windows.UI.Xaml.Media;
|
2017-10-27 17:15:18 +02:00
|
|
|
|
using Windows.UI.Xaml.Media.Imaging;
|
2021-06-14 21:41:37 +02:00
|
|
|
|
#endif
|
2017-10-27 17:15:18 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2018-08-08 23:31:52 +02:00
|
|
|
|
public static partial class ImageLoader
|
2017-10-27 17:15:18 +02:00
|
|
|
|
{
|
2019-06-13 21:38:01 +02:00
|
|
|
|
public static async Task<ImageSource> LoadImageAsync(IRandomAccessStream stream)
|
2018-08-15 23:29:03 +02:00
|
|
|
|
{
|
2018-12-09 17:14:32 +01:00
|
|
|
|
var image = new BitmapImage();
|
2019-06-17 18:09:28 +02:00
|
|
|
|
|
2018-12-09 17:14:32 +01:00
|
|
|
|
await image.SetSourceAsync(stream);
|
2019-06-17 18:09:28 +02:00
|
|
|
|
|
2018-12-09 17:14:32 +01:00
|
|
|
|
return image;
|
2018-08-15 23:29:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-02 11:35:20 +02:00
|
|
|
|
public static Task<ImageSource> LoadImageAsync(Stream stream)
|
2018-08-15 23:29:03 +02:00
|
|
|
|
{
|
2021-07-02 11:35:20 +02:00
|
|
|
|
return LoadImageAsync(stream.AsRandomAccessStream());
|
|
|
|
|
|
}
|
2018-08-15 23:29:03 +02:00
|
|
|
|
|
2021-07-02 11:35:20 +02:00
|
|
|
|
public static Task<ImageSource> LoadImageAsync(byte[] buffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var stream = new MemoryStream(buffer))
|
|
|
|
|
|
{
|
|
|
|
|
|
return LoadImageAsync(stream);
|
2018-08-15 23:29:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-15 01:39:07 +02:00
|
|
|
|
public static async Task<ImageSource> LoadImageAsync(string path)
|
2018-08-15 23:29:03 +02:00
|
|
|
|
{
|
2019-06-13 21:38:01 +02:00
|
|
|
|
ImageSource image = null;
|
2018-08-15 23:29:03 +02:00
|
|
|
|
|
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
|
{
|
2019-06-15 01:39:07 +02:00
|
|
|
|
var file = await StorageFile.GetFileFromPathAsync(Path.GetFullPath(path));
|
2018-08-15 23:29:03 +02:00
|
|
|
|
|
|
|
|
|
|
using (var stream = await file.OpenReadAsync())
|
|
|
|
|
|
{
|
2018-12-09 17:14:32 +01:00
|
|
|
|
image = await LoadImageAsync(stream);
|
2018-08-15 23:29:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-09 17:14:32 +01:00
|
|
|
|
return image;
|
2018-08-15 23:29:03 +02:00
|
|
|
|
}
|
2017-10-27 17:15:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|