[UWP] Using GetThumbnailAsync() sometimes will not preserve a gif transparency on its thumbnail

Fay Wang - MSFT 5,221 Reputation points
2019-12-12T08:44:48.373+00:00

Source link: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/fead741b-6da6-4d72-8f5e-b33099829da5/uwp-using-getthumbnailasync-sometimes-will-not-preserve-a-gif-transparency-on-its-thumbnail?forum=wpdevelop

----------

I'm developing an application and there is a page that we need to show a preview list of images from a folder.

I'm using the StorageFile.GetThumbnailAsync method to retrieve the thumbnail, but for some gif files it will not preserve the background transparency.

var thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem);  
  
BitmapImage bitmapImage = new BitmapImage();  
await bitmapImage.SetSourceAsync(thumbnail);  

I could not find a pattern for this behavior and it seems to be something related to Windows. On Windows Explorer, some gif files show the background as white and some as black, although they were created using the same lib.

When I open and show the gif file it works fine, only the thumbnail that comes with the black background.

Does anyone have any idea what could be causing that?

I've attached some images below of a sample app that I used to isolate the issue.

alt text
alt text
alt text

Here are the three pictures that can cause the same issue.
https://drive.google.com/file/d/16E4D_r_KnrIz91ATyi7ign2ZmogoZGti/view?usp=sharing
https://drive.google.com/file/d/1IYF2xqUmAypNT5coEZLXA7vD-tlCtfkv/view?usp=sharing
https://drive.google.com/file/d/1Yqi7Wvri5RFE2sEnITajPdPvqAZkJmck/view?usp=sharing

Universal Windows Platform (UWP)
{count} votes

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.