Here's a code I found sometime ago in the web. I'm not sure, but if I rember right it was from the sdk samples or a winrt blog
It all comes down to the WritabelBitmap Image ( like the other already posted), create a decoder and push it to the stream.
/// <summary>
///
/// </summary>
/// <param name="writeableBitmap"></param>
/// <param name="outputFile"></param>
/// <param name="encoderId"></param>
/// <returns></returns>
public static async Task SaveToFile(
this WriteableBitmap writeableBitmap,
IStorageFile outputFile,
Guid encoderId)
{
try
{
Stream stream = writeableBitmap.PixelBuffer.AsStream();
byte[] pixels = new byte[(uint)stream.Length];
await stream.ReadAsync(pixels, 0, pixels.Length);
using (var writeStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(encoderId, writeStream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
(uint)writeableBitmap.PixelWidth,
(uint)writeableBitmap.PixelHeight,
96,
96,
pixels);
await encoder.FlushAsync();
using (var outputStream = writeStream.GetOutputStreamAt(0))
{
await outputStream.FlushAsync();
}
}
}
catch (Exception ex)
{
string s = ex.ToString();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…