-
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