【问题标题】:Can you spot any problems with this DLL?你能发现这个 DLL 有什么问题吗?
【发布时间】:2015-01-07 20:09:57
【问题描述】:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EyesLib
{
    class Class1
    {

    public void drawEyes(int lookAtX, int lookAtY, int width, int height, Graphics eyeArea)
    {
        int xleft = 0, yleft = 0, xright = 0, yright = 0, xpleft = 0, ypleft = 0, xpright = 0, ypright = 0, reye = 0, rpupil = 0;
        xleft = width / 3;
        yleft = height / 2;
        xright = 2 * width / 3;
        yright = height / 2;
        reye = width / 9;
        rpupil = reye / 2;
        Bitmap bufl = new Bitmap(width, height);
        Graphics g = Graphics.FromImage(bufl);

        g.FillEllipse(Brushes.White, xleft - reye, yleft - reye, 2 * reye, 2 * reye);
        g.FillEllipse(Brushes.White, xright - reye, yright - reye, 2 * reye, 2 * reye);
        g.DrawEllipse(Pens.Black, xleft - reye, yleft - reye, 2 * reye, 2 * reye);
        g.DrawEllipse(Pens.Black, xright - reye, yright - reye, 2 * reye, 2 * reye);
        if ((lookAtX != xleft) || (lookAtY != yleft))
        {
            xpleft = (int)Math.Round(xleft + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xleft, 2) + Math.Pow(lookAtY - yleft, 2))) * (lookAtX - xleft));
            ypleft = (int)Math.Round(yleft + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xleft, 2) + Math.Pow(lookAtY - yleft, 2))) * (lookAtY - yleft));
        }
        else
        {
            xpleft = xleft;
            ypleft = yleft;
        }
        if ((lookAtX != xright) || (lookAtY != yright))
        {
            xpright = (int)Math.Round(xright + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xright, 2) + Math.Pow(lookAtY - yright, 2))) * (lookAtX - xright));
            ypright = (int)Math.Round(yright + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xright, 2) + Math.Pow(lookAtY - yright, 2))) * (lookAtY - yright));
        }
        else
        {
            xpright = xright;
            ypright = yright;
        }
        g.FillEllipse(Brushes.Black, xpleft - rpupil, ypleft - rpupil, 2 * rpupil, 2 * rpupil);
        g.FillEllipse(Brushes.Black, xpright - rpupil, ypright - rpupil, 2 * rpupil, 2 * rpupil);
        eyeArea.DrawImage(bufl, 0, 0);
        g.Dispose();



    }

    public void closeEyes(int width, int height, Graphics eyeArea)
    {
        int xleft = 0, yleft = 0, xright = 0, yright = 0, reye = 0, rpupil = 0;
        xleft = width / 3;
        yleft = height / 2;
        xright = 2 * width / 3;
        yright = height / 2;
        reye = width / 9;
        rpupil = reye / 2;
        eyeArea.FillEllipse(Brushes.Gray, xleft - reye, yleft - reye, 2 * reye, 2 * reye);
        eyeArea.FillEllipse(Brushes.Gray, xright - reye, yright - reye, 2 * reye, 2 * reye);

    }
}
}

尽管构建正确,但它在引用时无法被 Visual Studio 识别。 这也不是 .NET 版本问题。我尝试了所有 4/4.5/Client Profile 等。我什至重做了项目,我将 DLL 链接到该项目,但问题仍然存在。

【问题讨论】:

  • 请使标题相关。

标签: c# dll reference


【解决方案1】:

是的。你的课程不公开。尝试公开 Class1,我觉得它会解决您的问题。

至于为什么,如果不显式提供访问修饰符,一个类会默认为内部。由于您在外部程序集中引用您的类,因此 Intellisense 无法帮助您找到它,因为您的外部调用程序实际上无法访问它。

【讨论】:

  • @user4421334 很高兴。我更新了我的答案,为您提供更多背景信息。如果它解决了您的问题,将不胜感激选择正确答案:)
猜你喜欢
  • 2011-03-09
  • 1970-01-01
  • 2015-10-01
  • 2010-10-07
  • 1970-01-01
  • 1970-01-01
  • 2021-05-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多