Created
January 11, 2023 07:51
-
-
Save lbugnion/f9c35388a503a84c09ecf66120d8cf67 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 (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