Example #1
0
        private async Task <Thumbnail> LoadEmbeddedThumbnailAsyncImpl(
            IEntity entity,
            Size thumbnailAreaSize,
            CancellationToken cancellationToken)
        {
            using (var image = await _imageLoader.LoadThumbnailAsync(entity, cancellationToken)
                               .ConfigureAwait(false))
            {
                // the entity does not have an embedded thumbnail
                if (image == null)
                {
                    return(new Thumbnail(null, Size.Empty));
                }

                cancellationToken.ThrowIfCancellationRequested();

                // the entity does have an embedded thumbnail
                using (var thumbnail = _thumbnailGenerator.GetThumbnail(image, thumbnailAreaSize))
                {
                    var imageSize = new Size(image.Width, image.Height);
                    return(new Thumbnail(thumbnail.ToBitmap(), imageSize));
                }
            }
        }