OSMServer/RenderPath/PNGRenderer.cs

44 lines
1.1 KiB
C#
Raw Normal View History

using System.Drawing;
using System.Drawing.Imaging;
namespace RenderPath;
#pragma warning disable CA1416
public class PNGRenderer : Renderer
{
private readonly Image _image;
private readonly Graphics _graphics;
public PNGRenderer(int width, int height)
{
_image = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
_graphics = Graphics.FromImage(_image);
_graphics.Clear(Color.White);
}
public PNGRenderer(Image renderOver)
{
_image = renderOver;
_graphics = Graphics.FromImage(renderOver);
}
public override void DrawLine(float x1, float y1, float x2, float y2, int width, Color color)
{
Pen p = new Pen(color, width);
_graphics.DrawLine(p, x1, y1, x2, y2);
}
public override void DrawDot(float x, float y, int radius, Color color)
{
Brush b = new SolidBrush(color);
x -= radius / 2f;
y -= radius / 2f;
_graphics.FillEllipse(b, x, y, radius, radius);
}
public override void Save(string path)
{
_image.Save($"{path}.png", ImageFormat.Png);
}
}
#pragma warning restore CA1416