0

I am new to Windows app development. I want to resize the actual image to specific height and width. I have started using the following code but the resulting image is pixelated.

Please suggest for me better approach to resize image.

This is my code:

using (var sourceStream = await file.OpenAsync(FileAccessMode.Read)){

       BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceStream);
       BitmapTransform transform = new BitmapTransform() { ScaledHeight = 560, ScaledWidth = 580 };
       PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
           BitmapPixelFormat.Rgba8,
           BitmapAlphaMode.Straight,
           transform,
           ExifOrientationMode.RespectExifOrientation,
           ColorManagementMode.DoNotColorManage);

       using (var destinationStream = await destinationfile.OpenAsync(FileAccessMode.ReadWrite))
       {
           BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, destinationStream);
           encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight, 580, 560, 96, 96, pixelData.DetachPixelData());

           await encoder.FlushAsync();
       }
   }

1 Answers1

0

Here's solution without use of WritableBitmapEx

How to resize Image in C# WinRT/winmd?

Community
  • 1
  • 1
Farhan Ghumra
  • 15,180
  • 6
  • 50
  • 115
  • Thanks for your answer. As you can see we are already using similar approach,it would be very helpful if you can share some details using different approach – Sankar Dheksit Mar 09 '15 at 09:31
  • Link-only answers are discouraged on SO and this answer may end up on the Low Quality Posts queue as a result. I'd suggest including key parts from the link into the answer. – Daniel Kelley Mar 09 '15 at 10:46