How to resize Image in C# WinRT/winmd?

前端 未结 6 735
执念已碎
执念已碎 2020-11-27 18:54

I\'ve got simple question, but so far I\'ve found no answer: how to resize jpeg image in C# WinRT/WinMD project and save it as new jpeg?

I\'m developing Windows 8 Me

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 19:26

    Here is even shorter version, without overhead of accessing pixel data.

    using (var sourceFileStream = await sourceFile.OpenAsync(Windows.Storage.FileAccessMode.Read))
    using (var destFileStream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
    {
        BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceFileStream);
        BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(destFileStream, decoder);
        enc.BitmapTransform.ScaledWidth = newWidth;
        enc.BitmapTransform.ScaledHeight = newHeight;
        await enc.FlushAsync();
        await destFileStream.FlushAsync();
    }
    

提交回复
热议问题