Skip to content

Resizing via SKImage is blurry. Resizing via SKBitmap is great. #520

Closed
@dsyno

Description

@dsyno

Description

As @AndersMad discovered in #319 SKImage resizes very blurry, whereas resizing a SKBitmap works great.

Code

SKBitmap srcBitmap = ...
// Use attached "boat.jpg". A large image like this provides a more dramatic resize comparison
// (e.g. 5400x3615px). The more dramatic the resize, the more dramatic the resize quality between
// SKImage and SKBitmap.
int resizedWidth = 160, resizedHeight = 107;

// SKImage resizes blurry
using (var surface = SKSurface.Create(resizedWidth, resizedHeight, SKImageInfo.PlatformColorType,
	SKAlphaType.Premul))
using (var paint = new SKPaint())
{
	// high quality with antialiasing
	paint.IsAntialias = true;
	paint.FilterQuality = SKFilterQuality.High;

	// draw the bitmap to fill the surface
	surface.Canvas.DrawBitmap(srcBitmap, new SKRectI(0, 0, resizedWidth, resizedHeight),
		paint);
	surface.Canvas.Flush();

	// save
	using (var newImg = surface.Snapshot())
	using (SKData data = newImg.Encode(SKEncodedImageFormat.Jpeg, 100))
	using (Stream imgStream = data.AsStream())
	{
		// save the stream and look at the image. e.g. "blurry.jpg"
	}
}

// SKBitmap resizes crisp.
SKImageInfo resizeInfo = new SKImageInfo(resizedWidth, resizedHeight);
using (SKBitmap resizedSKBitmap = srcBitmap.Resize(resizeInfo, SKBitmapResizeMethod.Lanczos3))
using (SKImage newImg = SKImage.FromPixels(resizedSKBitmap.PeekPixels()))
using (SKData data = newImg.Encode(SKEncodedImageFormat.Jpeg, jpegQuality))
using (Stream imgStream = data.AsStream())
{
	// save the stream and look at the image. e.g. "crisp.jpg"
}

Expected Behavior

SKImage should be able to resize with the same good quality as SKBitmap

Actual Behavior

SKImage resizes very blurry.

Basic Information

  • Version with issue: 1.60.0
  • Last known good version:
  • IDE: Visual Studio
  • Platform Target Frameworks: .NET Core 2.0 (AWS Lambda)

Attachments

boat.jpg
boat

blurry.jpg (SKImage resize)
blurry

crisp.jpg (SKBitmap resize)
crisp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions