WriteableBitmap或BitmapImage到C ++ \ CLI中的StorageFile [英] WriteableBitmap or BitmapImage to StorageFile in C++\CLI
本文介绍了WriteableBitmap或BitmapImage到C ++ \ CLI中的StorageFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何想法如何将WriteableBitmap或BitmapImage保存到存储文件或使它们成为Stream以便我可以保存图像?
图像只能以那些格式找到它不是文件只是一个BitmapImage。
我在c#中知道这种方式如何用C ++编写它?
Any ideas how to save a WriteableBitmap or BitmapImage to a Storagefile or make them into Stream so i can save the image?
The image can be found only in those format its not a file its just a BitmapImage.
I know this way in c# any ideas how to make it in 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;
}
推荐答案
这篇关于WriteableBitmap或BitmapImage到C ++ \ CLI中的StorageFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文