3

I'm trying to downscale a jpeg image from 3028x4051 to 854x1171. This results in an image which is close to 1M pixels and maintains the aspect ratio. The original image is here. The image scales down very poorly though. Below is a section of the image. The top is the image scaled down in MS paint, the bottom it is scaled down programatically in C#. I've included the code I've used to downscale and save it. Anyone know what could be going on?

enter image description here

using (IRandomAccessStream sourceStream = await sourceFile.OpenAsync(FileAccessMode.Read)) { BitmapDecoder myDecoder = await GetDecoder(sourceStream); BitmapTransform myTransform = new BitmapTransform() { ScaledHeight = h, ScaledWidth = w }; await myDecoder.GetPixelDataAsync( BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, myTransform, ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage); BitmapEncoder myEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, destinationStream); myEncoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, w, h, 96, 96, pixelData.DetachPixelData()); await myEncoder.FlushAsync(); } 
2
  • 3
    Check Bitmap Interpolation Modes Commented Jun 2, 2015 at 12:55
  • I tried using WriteableBitmap myWriteableBitmap = img1.Resize(w, h height, WriteableBitmapExtensions.Interpolation.Bilinear); The image still comes out quite poorly Commented Jun 2, 2015 at 13:40

1 Answer 1

2

Where you create a new instance of BitmapTransform, you can specify the interpolation mode. Linear is the default mode, so to get a better result you need to try with Cubic or Fant.

using (IRandomAccessStream sourceStream = await sourceFile.OpenAsync(FileAccessMode.Read)) { BitmapDecoder myDecoder = await GetDecoder(sourceStream); BitmapTransform myTransform = new BitmapTransform() { ScaledHeight = h, ScaledWidth = w, InterpolationMode = BitmapInterpolationMode.Fant }; await myDecoder.GetPixelDataAsync( BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, myTransform, ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage); BitmapEncoder myEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, destinationStream); myEncoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, w, h, 96, 96, pixelData.DetachPixelData()); await myEncoder.FlushAsync(); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.