mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Version 4.12. Added MapControl.Images project, fixed assembly signing
This commit is contained in:
parent
3310f58912
commit
ac26c57a81
22 changed files with 1015 additions and 40 deletions
|
|
@ -7,11 +7,9 @@ using System.Diagnostics;
|
|||
using System.Threading.Tasks;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.Web.Http;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
#else
|
||||
using System.Net.Http;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
#endif
|
||||
|
||||
|
|
@ -24,23 +22,23 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public static HttpClient HttpClient { get; set; } = new HttpClient();
|
||||
|
||||
public static async Task<ImageSource> LoadImageAsync(Uri uri)
|
||||
public static async Task<BitmapSource> LoadImageAsync(Uri uri)
|
||||
{
|
||||
ImageSource imageSource = null;
|
||||
BitmapSource image = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (!uri.IsAbsoluteUri || uri.Scheme == "file")
|
||||
{
|
||||
imageSource = await LoadLocalImageAsync(uri);
|
||||
image = await LoadLocalImageAsync(uri);
|
||||
}
|
||||
else if (uri.Scheme == "http" || uri.Scheme == "https")
|
||||
{
|
||||
imageSource = await LoadHttpImageAsync(uri);
|
||||
image = await LoadHttpImageAsync(uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageSource = new BitmapImage(uri);
|
||||
image = new BitmapImage(uri);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -48,12 +46,12 @@ namespace MapControl
|
|||
Debug.WriteLine("ImageLoader: {0}: {1}", uri, ex.Message);
|
||||
}
|
||||
|
||||
return imageSource;
|
||||
return image;
|
||||
}
|
||||
|
||||
private static async Task<ImageSource> LoadHttpImageAsync(Uri uri)
|
||||
private static async Task<BitmapSource> LoadHttpImageAsync(Uri uri)
|
||||
{
|
||||
ImageSource imageSource = null;
|
||||
BitmapSource image = null;
|
||||
|
||||
using (var response = await HttpClient.GetAsync(uri))
|
||||
{
|
||||
|
|
@ -63,11 +61,11 @@ namespace MapControl
|
|||
}
|
||||
else if (IsTileAvailable(response.Headers))
|
||||
{
|
||||
imageSource = await LoadImageAsync(response.Content);
|
||||
image = await LoadImageAsync(response.Content);
|
||||
}
|
||||
}
|
||||
|
||||
return imageSource;
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ using System.Runtime.InteropServices.WindowsRuntime;
|
|||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Streams;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using Windows.Web.Http;
|
||||
using Windows.Web.Http.Headers;
|
||||
|
|
@ -18,14 +17,14 @@ namespace MapControl
|
|||
{
|
||||
public static partial class ImageLoader
|
||||
{
|
||||
public static async Task<ImageSource> LoadImageAsync(IRandomAccessStream stream)
|
||||
public static async Task<BitmapSource> LoadImageAsync(IRandomAccessStream stream)
|
||||
{
|
||||
var bitmapImage = new BitmapImage();
|
||||
await bitmapImage.SetSourceAsync(stream);
|
||||
return bitmapImage;
|
||||
var image = new BitmapImage();
|
||||
await image.SetSourceAsync(stream);
|
||||
return image;
|
||||
}
|
||||
|
||||
public static async Task<ImageSource> LoadImageAsync(byte[] buffer)
|
||||
public static async Task<BitmapSource> LoadImageAsync(byte[] buffer)
|
||||
{
|
||||
using (var stream = new InMemoryRandomAccessStream())
|
||||
{
|
||||
|
|
@ -35,7 +34,7 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
private static async Task<ImageSource> LoadImageAsync(IHttpContent content)
|
||||
private static async Task<BitmapSource> LoadImageAsync(IHttpContent content)
|
||||
{
|
||||
using (var stream = new InMemoryRandomAccessStream())
|
||||
{
|
||||
|
|
@ -45,9 +44,9 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
private static async Task<ImageSource> LoadLocalImageAsync(Uri uri)
|
||||
private static async Task<BitmapSource> LoadLocalImageAsync(Uri uri)
|
||||
{
|
||||
ImageSource imageSource = null;
|
||||
BitmapSource image = null;
|
||||
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
|
||||
|
||||
if (File.Exists(path))
|
||||
|
|
@ -56,11 +55,11 @@ namespace MapControl
|
|||
|
||||
using (var stream = await file.OpenReadAsync())
|
||||
{
|
||||
imageSource = await LoadImageAsync(stream);
|
||||
image = await LoadImageAsync(stream);
|
||||
}
|
||||
}
|
||||
|
||||
return imageSource;
|
||||
return image;
|
||||
}
|
||||
|
||||
internal static async Task<Tuple<IBuffer, TimeSpan?>> LoadHttpBufferAsync(Uri uri)
|
||||
|
|
|
|||
|
|
@ -10,14 +10,13 @@ using System.Linq;
|
|||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public static partial class ImageLoader
|
||||
{
|
||||
public static ImageSource LoadImage(Stream stream)
|
||||
public static BitmapSource LoadImage(Stream stream)
|
||||
{
|
||||
var bitmapImage = new BitmapImage();
|
||||
bitmapImage.BeginInit();
|
||||
|
|
@ -28,12 +27,12 @@ namespace MapControl
|
|||
return bitmapImage;
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(Stream stream)
|
||||
public static Task<BitmapSource> LoadImageAsync(Stream stream)
|
||||
{
|
||||
return Task.Run(() => LoadImage(stream));
|
||||
}
|
||||
|
||||
public static ImageSource LoadImage(byte[] buffer)
|
||||
public static BitmapSource LoadImage(byte[] buffer)
|
||||
{
|
||||
using (var stream = new MemoryStream(buffer))
|
||||
{
|
||||
|
|
@ -41,12 +40,12 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(byte[] buffer)
|
||||
public static Task<BitmapSource> LoadImageAsync(byte[] buffer)
|
||||
{
|
||||
return Task.Run(() => LoadImage(buffer));
|
||||
}
|
||||
|
||||
private static async Task<ImageSource> LoadImageAsync(HttpContent content)
|
||||
private static async Task<BitmapSource> LoadImageAsync(HttpContent content)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
|
|
@ -56,23 +55,23 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
private static ImageSource LoadLocalImage(Uri uri)
|
||||
private static BitmapSource LoadLocalImage(Uri uri)
|
||||
{
|
||||
ImageSource imageSource = null;
|
||||
BitmapSource image = null;
|
||||
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
using (var stream = File.OpenRead(path))
|
||||
{
|
||||
imageSource = LoadImage(stream);
|
||||
image = LoadImage(stream);
|
||||
}
|
||||
}
|
||||
|
||||
return imageSource;
|
||||
return image;
|
||||
}
|
||||
|
||||
private static Task<ImageSource> LoadLocalImageAsync(Uri uri)
|
||||
private static Task<BitmapSource> LoadLocalImageAsync(Uri uri)
|
||||
{
|
||||
return Task.Run(() => LoadLocalImage(uri));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue