-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ImageSourceService.cs
61 lines (53 loc) · 1.72 KB
/
ImageSourceService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#nullable enable
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace Microsoft.Maui
{
public abstract class ImageSourceService : IImageSourceService
{
public ImageSourceService(ILogger? logger = null)
{
Logger = logger;
}
public ILogger? Logger { get; }
#if __ANDROID__
public virtual async Task<IImageSourceServiceResult?> LoadDrawableAsync(
IImageSource imageSource,
Android.Widget.ImageView imageView,
CancellationToken cancellationToken = default)
{
var realResult = await GetDrawableAsync(imageSource, imageView.Context!, cancellationToken);
if (realResult is null)
{
imageView.SetImageDrawable(null);
return null;
}
imageView.SetImageDrawable(realResult.Value);
var result = new ImageSourceServiceLoadResult(
realResult.IsResolutionDependent,
() => realResult.Dispose());
return result;
}
public abstract Task<IImageSourceServiceResult<Android.Graphics.Drawables.Drawable>?> GetDrawableAsync(
IImageSource imageSource,
Android.Content.Context context,
CancellationToken cancellationToken = default);
#elif __IOS__
public abstract Task<IImageSourceServiceResult<UIKit.UIImage>?> GetImageAsync(
IImageSource imageSource,
float scale = 1,
CancellationToken cancellationToken = default);
#elif TIZEN || __TIZEN__
public abstract Task<IImageSourceServiceResult<MauiImageSource>?> GetImageAsync(
IImageSource imageSource,
CancellationToken cancellationToken = default);
#elif WINDOWS
public abstract Task<IImageSourceServiceResult<UI.Xaml.Media.ImageSource>?> GetImageSourceAsync(
IImageSource imageSource,
float scale = 1,
CancellationToken cancellationToken = default);
#endif
}
}