在WIndows 8 Store App中更改图像的分辨率

时间:2013-10-08 10:02:38

标签: c# image-processing windows-store-apps

我创建了一个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?感谢

0 个答案:

没有答案