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;

No need to be task it can be void no problem...

有帮助吗?

解决方案

Well, first thing is - if you loaded the BitmapImage in the first place - then you have access to the source file, so the easiest solution would be to copy the source file. As for the WriteableBitmap - it's a bit similar to the C# version, but of course slightly more complicated as you start working with COM-like techniques. See if James's answer to my question about getting access to the pixels helps you a bit:

How to get access to WriteableBitmap.PixelBuffer pixels with C++?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top