public async Task <Stream> DownloadImageAsync(int itemId, int imageIndex, SimaLandImageSize imageSize)
        {
            if (itemId < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(itemId));
            }
            if (imageIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(imageIndex));
            }

            if (!Enum.IsDefined(typeof(SimaLandImageSize), imageSize))
            {
                throw new InvalidEnumArgumentException(nameof(imageSize), (int)imageSize, typeof(SimaLandImageSize));
            }

            await AuthorizeAsync();

            var itemResponse = await _apiClient.GetItemAsync(itemId);

            var basePhotoUri = new Uri(itemResponse.BasePhotoUrl);
            var photoUri     = new Uri(basePhotoUri, $"{imageIndex}/{imageSize.GetEnumMemberValue()}");

            var httpResponseMessage = await _httpClient.GetAsync(photoUri);

            httpResponseMessage.EnsureSuccessStatusCode();
            var imageStream = await httpResponseMessage.Content.ReadAsStreamAsync();

            return(imageStream);
        }
Ejemplo n.º 2
0
        private async Task <SKBitmap> GetImageAsync(int itemId, int imageIndex, SimaLandImageSize imageSize)
        {
            await using var stream = await _simaLandService.DownloadImageAsync(itemId, imageIndex, imageSize);

            return(SKBitmap.Decode(stream));
        }