1

我创建了一个 Windows 商店应用程序。我想调整图像大小,下面的代码是保存图像:

private async void saveImage(StorageFile destinationFile)
{
     if (destinationFile != null)
     {
         using (var readStream = await sourceFile.OpenReadAsync())
         {
               var decoder = await BitmapDecoder.CreateAsync(readStream);
               using (InMemoryRandomAccessStream writeStream = new InMemoryRandomAccessStream())
               {
                    BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(writeStream, decoder);
                    encoder.BitmapTransform.Bounds = new BitmapBounds()
                    {
                         X = (uint)Math.Round(selectedLeft, 0),
                         Y = (uint)Math.Round(selectedTop, 0),
                         Width = (uint)Math.Round(selectedWidth, 0),
                         Height = (uint)Math.Round(selectedHeight, 0),
                    };
                    await encoder.FlushAsync();
                    using (var stream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
                    {
                         await RandomAccessStream.CopyAndCloseAsync(writeStream.GetInputStreamAt(0), stream.GetOutputStreamAt(0));
                    }
               }
       }
}

保存的图像尺寸为 320x480。如何将大小调整为 960x1240?谢谢

4

0 回答 0