Esempio n. 1
0
        /// <summary>
        /// Create a thumbnail image from the input. The thumbnail is taken from the image file in the case that the file has one.
        /// Otherwise it will be a new image that is created from the image file.
        /// </summary>
        /// <param name="decoder">Bitmap decoder.</param>
        /// <param name="expectedWidth"> Expected width.</param>
        /// <param name="expectedHeight">Expected height.</param>
        /// <returns>a new image with smallest size that is larger than the input dimension.</returns>
        public static async Task <SoftwareBitmap> CreateThumbnail(BitmapDecoder decoder, uint expectedWidth, uint expectedHeight)
        {
            BitmapDecoder decoder2;

            try
            {
                var thumbnail = await decoder.GetThumbnailAsync();

                decoder2 = await BitmapDecoder.CreateAsync(thumbnail);
            }
            catch
            {
                decoder2 = null;
            }

            if (decoder2 == null)
            {
                try
                {
                    var preview = await decoder.GetPreviewAsync();

                    decoder2 = await BitmapDecoder.CreateAsync(preview);
                }
                catch
                {
                    decoder2 = null;
                }
            }

            if (decoder2 == null)
            {
                decoder2 = decoder;
            }

            return(await CreateResizedBitmap(decoder2, expectedWidth, expectedHeight, BitmapInterpolationMode.Linear));
        }