-
StackOverflow 文档
-
uwp 教程
-
图片
-
将位图(例如,从剪贴板内容)转换为 PNG
IRandomAccessStreamReference bitmap = GetBitmap();
IRandomAccessStreamWithContentType stream = await bitmap.OpenReadAsync();
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
var pixels = await decoder.GetPixelDataAsync();
var outStream = new InMemoryRandomAccessStream();
// Create encoder for PNG
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, outStream);
// Get pixel data from decoder and set them for encoder
encoder.SetPixelData(decoder.BitmapPixelFormat,
BitmapAlphaMode.Ignore, // Alpha is not used
decoder.OrientedPixelWidth,
decoder.OrientedPixelHeight,
decoder.DpiX, decoder.DpiY,
pixels.DetachPixelData());
await encoder.FlushAsync(); // Write data to the stream
// Here you can use your stream