This code worked for me. Before you try, make sure that your recordable card has a transparent background (you can check by assigning the image source to the image controller). If not, make the background transparent from the controller from which it came.
var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; var file = await localFolder.CreateFileAsync("temp.png", CreationCollisionOption.ReplaceExisting); using (var ras = await file.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None)) { WriteableBitmap bitmap = imageSource; var stream = bitmap.PixelBuffer.AsStream(); byte[] buffer = new byte[stream.Length]; await stream.ReadAsync(buffer, 0, buffer.Length); BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ras); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)bitmap.PixelWidth, (uint)bitmap.PixelHeight, 96.0, 96.0, buffer); await encoder.FlushAsync(); }
Take a look at this!
gayan1991
source share