The fastest way to flush SoftwareBitmap to stream

0

Due to non-effective BitmapEncoder.FlushAsync() method, I want to get to know if there is other way to save SoftwareBitmap data to stream. My code (a little bit simplified solution) :

using (InMemoryRandomAccessStream accessStream = new InMemoryRandomAccessStream())
{
    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(_inputFormat, accessStream);
    // Set the software bitmap
    encoder.SetSoftwareBitmap(input);
    encoder.IsThumbnailGenerated = true;
    try
    {
        await encoder.FlushAsync();
    }
    catch (Exception err)
    {
        switch (err.HResult)
        {
            case unchecked((int)0x88982F81): //WINCODEC_ERR_UNSUPPORTEDOPERATION
                                                // If the encoder does not support writing a thumbnail, then try again
                                                // but disable thumbnail generation.

                encoder.IsThumbnailGenerated = false;
                break;
            default:
                throw err;
        }
    }

    if (encoder.IsThumbnailGenerated == false)
    {
        await encoder.FlushAsync();
    }

}

Thanks a lot for all answers.

c#
uwp
asked on Stack Overflow Apr 19, 2018 by Sarnapa

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0