Skip to content

Instantly share code, notes, and snippets.

@bleroy
Last active June 9, 2017 17:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bleroy/2c6df8cb4a951364091737a018142f65 to your computer and use it in GitHub Desktop.
Save bleroy/2c6df8cb4a951364091737a018142f65 to your computer and use it in GitHub Desktop.
using SkiaSharp;
const int size = 150;
const int quality = 75;
using (var input = File.OpenRead(inputPath))
{
using (var inputStream = new SKManagedStream(input))
{
using (var original = SKBitmap.Decode(inputStream))
{
int width, height;
if (original.Width > original.Height)
{
width = size;
height = original.Height * size / original.Width;
}
else
{
width = original.Width * size / original.Height;
height = size;
}
using (var resized = original
.Resize(new SKImageInfo(width, height), SKBitmapResizeMethod.Lanczos3))
{
if (resized == null) return;
using (var image = SKImage.FromBitmap(resized))
{
using (var output =
File.OpenWrite(OutputPath(path, outputDirectory, SkiaSharpBitmap)))
{
image.Encode(SKImageEncodeFormat.Jpeg, Quality)
.SaveTo(output);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment