【问题标题】:Draw circle and X spots inside an image by list of x,y coordinates.Asp C#通过 x,y 坐标列表在图像内绘制圆圈和 X 点。Asp C#
【发布时间】:2014-04-30 23:02:28
【问题描述】:

我有一个 asp:image

    <asp:Image ID="ImageMap1" runat="server" ImageUrl="~/images/court.jpg"></asp:Image>

我还有 4 个带有 int X,Y 坐标的列表

      int[] GreenCircleX = new int[4] { 10, 20, 22, 25};
      int[] GreenCircleY = new int[4] { 10, 20, 22, 25};
      int[] RedxX = new int[4] { 15, 6, 50, 32};
      int[] RedxY = new int[4] { 15, 8, 50, 23};

我想从图像内的 GreenCircleX,Y 坐标绘制(如果可能的话)绿色小圆圈:court.jpg 。还有来自同一图像中 RedxX,Y 坐标的红色 X 点。不需要任何可点击的东西.

图片法庭.jpg: 和可能的结果

有什么建议吗?

【问题讨论】:

  • 是什么阻止了您尝试自己实现它?您明确面临什么问题?
  • 我可以使用列表和整数,但我不知道如何通过 c# 在图像中绘制
  • 也许这可以让你开始:stackoverflow.com/a/11403059/2186023(是的,我知道线,而不是圈,但drawing on an image 两者基本相同;))
  • 这可以用于asp吗?如何将图像作为位图获取?
  • 这是一个不同的问题,这就是为什么你需要在你的问题中保持精确,因为你最初的问题实际上是 2:1. 如何在通过文件 2 加载的图像上绘图。如何在 asp.net 网页上获取动态绘制的图像

标签: c# asp.net image coordinates draw


【解决方案1】:

我终于做到了。正如 DrCopyPaste 所说,您必须加载图像,绘制并保存它。使用以下代码绘制绿色圆圈和红色 X。

       Bitmap bitMapIm = new
    System.Drawing.Bitmap(Server.MapPath(@"images\court.jpg"));
    Graphics graphicIm = Graphics.FromImage(bitMapIm);

    Pen penGreen = new Pen(Color.Green, 3);
    Pen penRed = new Pen(Color.Red, 3);
    for (int i = 0; i < GreenCircleX.Count; i++)
    {        
    graphicIm.DrawEllipse(penGreen, GreenCircleX[i] ,GreenCircleY[i], 7, 7);

    graphicIm.DrawString("X", new Font("Arial", 10, FontStyle.Bold), Brushes.Red, RedxX[i] ,RedxY[i]);
    }
    bitMapIm.Save(Server.MapPath(@"images\courtout.jpg"), ImageFormat.Jpeg);
    graphicIm.Dispose();
    bitMapIm.Dispose();

所以我必须使用 courtout.jpg 作为 url

         <asp:Image ID="ImageMap1" runat="server" ImageUrl="~/images/courtout.jpg"></asp:Image>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多