Exemple #1
0
        private async Task <ImageData> TryOpenSourceAsync(CancellationToken ct, int?targetWidth, int?targetHeight)
        {
            var surface = new SkiaCompositionSurface();

            try
            {
                if (UriSource != null)
                {
                    if (UriSource.Scheme == "http" || UriSource.Scheme == "https")
                    {
                        var client   = new HttpClient();
                        var response = await client.GetAsync(UriSource, HttpCompletionOption.ResponseContentRead, ct);

                        var imageStream = await response.Content.ReadAsStreamAsync();

                        return(OpenFromStream(targetWidth, targetHeight, surface, imageStream));
                    }
                    else if (UriSource.Scheme == "ms-appx")
                    {
                        var path = UriSource.PathAndQuery;

                        var filePath = GetScaledPath(path);

                        using var fileStream = File.OpenRead(filePath);

                        return(OpenFromStream(targetWidth, targetHeight, surface, fileStream));
                    }
                }
                else if (_stream != null)
                {
                    return(OpenFromStream(targetWidth, targetHeight, surface, _stream.AsStream()));
                }
            }
            catch (Exception e)
            {
                return(new ImageData()
                {
                    Error = e
                });
            }

            return(default);