Skip to content

Instantly share code, notes, and snippets.

@HemulGM
Created November 22, 2019 10:52
Show Gist options
  • Save HemulGM/0f9e1888ad25272319fe83e1cce37cd1 to your computer and use it in GitHub Desktop.
Save HemulGM/0f9e1888ad25272319fe83e1cce37cd1 to your computer and use it in GitHub Desktop.
function CreateAvatar(Source: TGraphic; Mask: TPngImage): TPngImage;
var
BMPSmooth: TBitmap;
Av: TPngImage;
begin
BMPSmooth := SmoothStrechDraw(Source, TSize.Create(Mask.Width, Mask.Height));
Result := TPngImage.CreateBlank(COLOR_RGB, 16, Mask.Width, Mask.Height);
Result.Canvas.Draw(0, 0, BMPSmooth);
with TDirect2DCanvas.Create(Result.Canvas, Rect(0, 0, Mask.Width, Mask.Height)) do
begin
BeginDraw;
Brush.Style := bsClear;
Pen.Width := 3;
Pen.Color := $0081B543;
Ellipse(Rect(0, 0, Mask.Width - 1, Mask.Height - 1));
EndDraw;
Free;
end;
BMPSmooth.Free;
Result.CreateAlpha;
ApplyMask(0, 0, Mask, Result);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment