如何在mvc 6 .net core 5中使用图像captha?

时间:2016-03-09 14:17:52

标签: asp.net bitmap asp.net-core-mvc

我想知道如何在mvc 6 .net core 5 GDi +中使用图像绘制?参考 systeam.drawing库不在.net core 5中使用我想使用.net core 5

的代码
private static Bitmap GenerateRandomCaptchaImage(string text)
{
    var bitmap = new Bitmap(200, 150);
    var g = Graphics.FromImage(bitmap);

    var pen = new Pen(Color.Yellow);
    var rect = new System.Drawing.Rectangle(0, 0, 200, 150);
    var brush = new SolidBrush(Color.Blue);

   g.DrawRectangle(pen, rect);
   g.FillRectangle(brush, rect);           
   g.DrawString(text, new Font("Georgia", 20), new SolidBrush(Color.Black), 10, 50);

   DrawRandomLines(g);

    g.Dispose();
    return bitmap;
}

private static System.Drawing.Point[] GetRandomPoints()
{
    var rand = new Random();

    System.Drawing.Point[] points = { new System.Drawing.Point(rand.Next(10, 150), rand.Next(10, 150)), new System.Drawing.Point(rand.Next(10, 100), rand.Next(10, 100)) };

    return points;
}

private static void DrawRandomLines(Graphics g)
{
    SolidBrush green = new SolidBrush(Color.Green);

    for (int i = 0; i < 20; i++)
    {
        g.DrawLines(new Pen(green, 2), GetRandomPoints());
    }
}

1 个答案:

答案 0 :(得分:0)

(。目前?)在.net Core中使用system.drawing的解决方案中没有完全支持 而是尝试使用Mono的开源System.Drawing实现。

哪个是System.Drawing重播? https://github.com/dotnet/corefx/issues/3634

进一步阅读: https://github.com/dotnet/corefx/issues/5921