所以我可以保存图像?该图像只能以那些格式找到,它不是文件,它只是一个 BitmapImage。
我在 C# 中以这种方式知道如何在 C++ 中实现它?
private static async Task<StorageFile> SaveAsJpeg(WriteableBitmap wb)
{
byte[] pixels;
using (var stream = wb.PixelBuffer.AsStream())
{
pixels = new byte[(uint)stream.Length];
await stream.ReadAsync(pixels, 0, pixels.Length);
}
var name = String.Format("{0}_{1:yyyy-MM-dd_HH-mm-ss}.jpg", "MyApp", DateTime.Now);
var outputFile = await KnownFolders.PicturesLibrary.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);
using (var writeStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, writeStream);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied,
(uint)wb.PixelWidth, (uint)wb.PixelHeight,
96, 96, pixels);
await encoder.FlushAsync();
using (var outputStream = writeStream.GetOutputStreamAt(0))
{
await outputStream.FlushAsync();
}
}
return outputFile;
不需要任务它可以是无效的没问题...