mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-01-03 15:20:22 +01:00
Update ImageLoader.WPF.cs
This commit is contained in:
parent
eade7c4dad
commit
0714a04a92
|
|
@ -11,7 +11,39 @@ namespace MapControl
|
|||
{
|
||||
public static partial class ImageLoader
|
||||
{
|
||||
public static ImageSource LoadImage(Stream stream)
|
||||
public static Task<ImageSource> LoadImageAsync(Stream stream)
|
||||
{
|
||||
return Task.Run(() => LoadImage(stream));
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(byte[] buffer)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
using (var stream = new MemoryStream(buffer))
|
||||
{
|
||||
return LoadImage(stream);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(string path)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using (var stream = File.OpenRead(path))
|
||||
{
|
||||
return LoadImage(stream);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static ImageSource LoadImage(Stream stream)
|
||||
{
|
||||
var bitmapImage = new BitmapImage();
|
||||
|
||||
|
|
@ -23,43 +55,5 @@ namespace MapControl
|
|||
|
||||
return bitmapImage;
|
||||
}
|
||||
|
||||
public static ImageSource LoadImage(byte[] buffer)
|
||||
{
|
||||
using (var stream = new MemoryStream(buffer))
|
||||
{
|
||||
return LoadImage(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageSource LoadImage(string path)
|
||||
{
|
||||
ImageSource image = null;
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
using (var stream = File.OpenRead(path))
|
||||
{
|
||||
image = LoadImage(stream);
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(Stream stream)
|
||||
{
|
||||
return Task.Run(() => LoadImage(stream));
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(byte[] buffer)
|
||||
{
|
||||
return Task.Run(() => LoadImage(buffer));
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(string path)
|
||||
{
|
||||
return Task.Run(() => LoadImage(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue