2017-10-27 17:15:18 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2019-03-27 18:39:59 +01:00
|
|
|
|
// © 2019 Clemens Fischer
|
2017-10-27 17:15:18 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
2018-08-15 23:29:03 +02:00
|
|
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
2017-10-27 17:15:18 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Windows.Storage;
|
|
|
|
|
|
using Windows.Storage.Streams;
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2018-08-08 23:31:52 +02:00
|
|
|
|
public static partial class ImageLoader
|
2017-10-27 17:15:18 +02:00
|
|
|
|
{
|
2019-07-13 00:08:56 +02:00
|
|
|
|
public static Task<ImageSource> LoadImageAsync(Stream stream)
|
|
|
|
|
|
{
|
|
|
|
|
|
return LoadImageAsync(stream.AsRandomAccessStream());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-13 21:38:01 +02:00
|
|
|
|
public static async Task<ImageSource> LoadImageAsync(byte[] buffer)
|
2018-08-15 23:29:03 +02:00
|
|
|
|
{
|
|
|
|
|
|
using (var stream = new InMemoryRandomAccessStream())
|
|
|
|
|
|
{
|
|
|
|
|
|
await stream.WriteAsync(buffer.AsBuffer());
|
|
|
|
|
|
stream.Seek(0);
|
|
|
|
|
|
|
2018-08-16 19:43:16 +02:00
|
|
|
|
return await 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
|
|
|
|
}
|
|
|
|
|
|
}
|