【问题标题】:The type or namespace name could not be found, Beginner in C#找不到类型或命名空间名称,C# 中的初学者
【发布时间】:2014-06-09 14:47:06
【问题描述】:

您好,我是 C# 的初学者,我正在尝试一个在线示例来使用 Kinect for Windows 设备。

我认为问题在于我的参考,但不知道该怎么做

我认为这与 .Net 框架有关,因为示例似乎基于旧版本的框架

PS:我确实使用“添加引用”引用了 kinect dll

项目参考是:

Microsoft.CSharp
Microsoft.Kinect
System
System.ComponentModel.Composition
System.ComponentModel.DataAnnotations
System.Core
System.Data
System.Data.DataSetExtensions
System.Deployment
System.Drawing
System.Runtime.DurableInstancing
System.Runtime.Remoting
System.Runtime.Serialization
System.Windows.Forms
System.Runtime.Serialization.Formatters.Soap
System.Xml
System.Xml.Linq

我得到的错误是:

错误 1:找不到类型或命名空间名称“运行时”行 20

错误 2:类型或命名空间名称“ImageFrameReadyEventArgs”可能 找不到第 43 行

错误 2:找不到类型或命名空间名称“PlanarImage” 第 50 行

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Drawing.Imaging;
using System.Runtime.InteropServices;

using Microsoft.Kinect;

namespace HelloKinectWorld
{
    public partial class Form1 : Form
    {

        Runtime nui = Runtime.Kinects[0];


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(
        object sender, EventArgs e)
        {
            nui.Initialize(RuntimeOptions.UseColor);
            nui.VideoStream.Open(
            ImageStreamType.Video,
            2,
            ImageResolution.Resolution640x480,
             ImageType.Color);
            nui.VideoFrameReady +=
            new EventHandler<ImageFrameReadyEventArgs>(
            FrameReady);
        }

        void FrameReady(object sender,
        ImageFrameReadyEventArgs e)
        {
            PlanarImage Image = e.ImageFrame.Image;
            Bitmap bmap = PImageToBitmap(Image);
            pictureBox1.Image = bmap;
        }

        Bitmap PImageToBitmap(PlanarImage PImage)
        {
            Bitmap bmap = new Bitmap(
            PImage.Width,
            PImage.Height,
            PixelFormat.Format32bppRgb);
            BitmapData bmapdata = bmap.LockBits(
            new Rectangle(0, 0, PImage.Width,
            PImage.Height),
             ImageLockMode.WriteOnly,
            bmap.PixelFormat);
            IntPtr ptr = bmapdata.Scan0;
            Marshal.Copy(PImage.Bits,
            0,
            ptr,
            PImage.Width *
            PImage.BytesPerPixel *
             PImage.Height);
            bmap.UnlockBits(bmapdata);
            return bmap;
        }

        private void button1_Click(
        object sender, EventArgs e)
        {
            nui.NuiCamera.ElevationAngle += 4;
        }

        private void button2_Click(
        object sender,
        EventArgs e)
        {
            nui.NuiCamera.ElevationAngle -= 4;
        }

        private void Form1_FormClosing(
                     object sender,
                     FormClosingEventArgs e)
        {
            nui.Uninitialize();
        }
    }
}

【问题讨论】:

  • 您能否也列出项目引用,因为我猜您可能缺少其中之一。
  • 如果您右键单击 Runtime 关键字,您不会获得导入某些库的选项吗?
  • @Jon Hanna 我刚刚列出了参考文献
  • @me how 它没有任何建议,有一个解决选项可以输入 System.Runtime 或 Microsoft.Runtime 但这会导致另一个错误 'Runtime' is a namespace not type
  • 我认为那里存在名称冲突。如果你有两个库,它们的内部类使用相同的名称,那么你必须为命名空间创建别名或明确限定你将要使用的类。

标签: c# .net reference namespaces kinect


【解决方案1】:

这通常意味着您需要添加一些对程序集的引用。您正在导入 Microsoft.Kinect,但您应该检查您实际上是在从您的 Visual Studio 项目中引用 microsoft.kinect dll。

您可以在 Visual Studio 项目中的引用文件夹中查看它。如果您尚未将所需的 kinect dll 添加为项目的一部分,请使用上下文菜单和“添加引用”来添加。

【讨论】:

  • 我确实使用“添加引用”引用了 microsoft.kinect dll,我忘了提到,现在可以,但这似乎不是问题
【解决方案2】:

您使用的是哪个版本的 Kinect SDK?在最新版本 (1.8) 中,Runtime 很可能是 KinectSensor, ImageFrameReadyEventArgs 将是 ColorFrameReadyEventArgs(或 AllFramesReadyEventArgs)和 PlanarImage 将是 ColorImage

【讨论】:

    猜你喜欢
    • 2013-03-25
    • 2011-06-28
    • 2021-08-19
    • 1970-01-01
    • 2017-07-12
    • 2011-05-13
    • 2011-02-24
    • 2012-06-19
    相关资源
    最近更新 更多