将SoftwareBitmap刷新为流的最快方法

时间:2018-04-19 20:14:36

标签: c# uwp

由于BitmapEncoder.FlushAsync()方法无效,我想了解是否有其他方法可以将SoftwareBitmap数据保存到流中。我的代码(一点点简化的解决方案):

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();
    }

}

非常感谢所有答案。

0 个答案:

没有答案