Last active
June 9, 2017 17:35
-
-
Save bleroy/2c6df8cb4a951364091737a018142f65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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