private bool TryProcessOriginalFile(string path)
{
using var stream = File.OpenRead(Path.Combine(path, "original"));
var bmpLossless = SKBitmap.Decode(stream);
if (bmpLossless == null)
{
return false;
}
//Only using it isnt trustful
if (bmpLossless.Width > bmpLossless.Height)
{
bmpLossless = RotateLandscapeToPortrait(bmpLossless);
}
var outPathJpg = Path.Combine(path, "original.jpg");
using (var outFileJpg = new FileStream(outPathJpg, FileMode.Create))
{
bmpLossless.Encode(SKEncodedImageFormat.Jpeg, 70).SaveTo(outFileJpg);
}
bmpLossless.Dispose();
return true;
}
private static SKBitmap RotateLandscapeToPortrait(SKBitmap bmpLossless)
{
var rotated = new SKBitmap(bmpLossless.Height, bmpLossless.Width);
using (var canvas = new SKCanvas(rotated))
{
canvas.Clear();
canvas.Translate(0, bmpLossless.Width);
canvas.RotateDegrees(-90);
canvas.DrawBitmap(bmpLossless, new SKPoint());
}
return rotated;
}