Skip to content

Instantly share code, notes, and snippets.

@lbugnion
Created January 11, 2023 07:51
Show Gist options
  • Save lbugnion/f9c35388a503a84c09ecf66120d8cf67 to your computer and use it in GitHub Desktop.
Save lbugnion/f9c35388a503a84c09ecf66120d8cf67 to your computer and use it in GitHub Desktop.
using (headshotStream)
{
using (var maskStream = File.Open(@"C:\Users\lbugn\Desktop\HeadshotMask.png", FileMode.Open))
{
var maskBitmap = SKBitmap.Decode(maskStream);
var headshotBitmap = SKBitmap.Decode(headshotStream);
using (var surface = SKSurface.Create(new SKImageInfo(1000, 1000)))
{
var canvas = surface.Canvas;
canvas.DrawBitmap(maskBitmap, 0, 0);
using (var paint = new SKPaint())
{
paint.BlendMode = SKBlendMode.SrcIn;
canvas.DrawBitmap(headshotBitmap, new SKRect(0, 0, 1000, 1000), paint);
var final = surface.Snapshot();
using (var encoded = final.Encode(SKEncodedImageFormat.Png, 100))
{
using (var outputStream = File.OpenWrite(@"C:\Users\lbugn\Desktop\result.png"))
{
encoded.SaveTo(outputStream);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment