How to get thumbnails from PNG files?

Hong 1,211 Reputation points
2022-02-20T18:11:09.417+00:00

This is related to this question.

StorageItemThumbnail sit = await storageFileImage.GetThumbnailAsync(ThumbnailMode.PicturesView);  

The above code works fine with JPG files but throws the following error for PNG files:

System.Exception: Exception from HRESULT: 0x80270301
Stack Trace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x21
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x70
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x38
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x17

Could anyone offer a tip on how to get thumbnails of PNG files?

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 84,281 Reputation points
    2022-02-20T19:59:58.093+00:00

    Like in the other thread, it works fine for me, with this .PNG for testing : Butterfly.png
    (Windows 10 21H1, VS 2022)

    Test

                    // Path = "E:\\Sources\\UWP_Test2\\UWP_Test2\\bin\\x86\\Debug\\AppX"  
                    Windows.Storage.StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; // Windows.Storage.ApplicationData.Current.LocalFolder;  
                    Windows.Storage.StorageFile storageFileImage = await storageFolder.GetFileAsync("Butterfly.png");  
                    Windows.Storage.FileProperties.StorageItemThumbnail siThumbnail = await storageFileImage.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.PicturesView,  
                    300, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale);  
    

    When I debug :

    176118-getthumbnailasync.jpg

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.