mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 21:26:31 +00:00
put better caption in result image
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace Azaion.Common.Extensions;
|
||||
|
||||
public static class GraphicsExtensions
|
||||
{
|
||||
public static void DrawTextBox(this Graphics g, string text, PointF position, Brush background, Brush foreground)
|
||||
{
|
||||
using var textFont = new Font(FontFamily.GenericSerif, 14);
|
||||
using var stringFormat = new StringFormat();
|
||||
stringFormat.LineAlignment = StringAlignment.Near;
|
||||
stringFormat.Alignment = StringAlignment.Center;
|
||||
|
||||
var padding = 1.0f;
|
||||
var textSize = g.MeasureString(text, textFont);
|
||||
|
||||
var backgroundRect = new RectangleF(
|
||||
position.X - textSize.Width / 2.0f - padding,
|
||||
position.Y - padding,
|
||||
textSize.Width + 2 * padding,
|
||||
textSize.Height + 2 * padding
|
||||
);
|
||||
|
||||
g.FillRectangle(background, backgroundRect);
|
||||
g.DrawString(text, textFont, foreground, position, stringFormat);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user