Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main()
- {
- DrawTextToPng("Hogemoge-fugaf@-!!!$&'&piyo_-=hiogfew", 10);
- }
- public void DrawTextToPng(string text, int xPadding = 0)
- {
- // draw some text
- var paint = new SKPaint
- {
- Color = SKColors.White,
- IsAntialias = true,
- Style = SKPaintStyle.Fill,
- TextAlign = SKTextAlign.Center,
- TextSize = 24
- };
- var width = paint.MeasureText(text);
- var info = new SKImageInfo((int)width + xPadding, 50);
- using (var surface = SKSurface.Create(info))
- {
- var canvas = surface.Canvas;
- // make sure the canvas is blank
- canvas.Clear(SKColors.Black);
- var coord = new SKPoint(info.Width / 2, (info.Height + paint.TextSize) / 2);
- canvas.DrawText(text, coord, paint);
- // save the file
- using (var image = surface.Snapshot())
- using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
- using (var stream = File.OpenWrite("output.png"))
- {
- data.SaveTo(stream);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement