DataPackageView Bitmap looses transparency

tscholl89 1 Reputation point
2022-06-10T06:34:50.787+00:00

Using the .NET framework, when retrieving the image from the clipboard by converting the IRandomAccessStreamReference, the transparency on .PNG images is lost. How can i prevent this?

var content = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();  
if (content.Contains(StandardDataFormats.Bitmap))  
{  
IRandomAccessStreamReference imageReceived = await content.GetBitmapAsync();  
BitmapImage bitmap = null;  
                     
using (IRandomAccessStreamWithContentType imageStream = await imageReceived.OpenReadAsync())  
{  
        bitmap = new BitmapImage();  
        bitmap.BeginInit();  
        bitmap.StreamSource = imageStream.AsStream();  
        bitmap.CacheOption = BitmapCacheOption.OnLoad;  
        bitmap.EndInit();  
        bitmap.Freeze();  
    }  
}  
Universal Windows Platform (UWP)
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,678 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,286 questions
{count} votes