请教几个关于类和方法的基础问题

可爱的芒果酱 2015-05-11 11:53:47
我是新手,遇到了几个问题,请教下

private void kinectSensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
{
if (depthImageFrame != null)
{
pixelData = new short[depthImageFrame.PixelDataLength];
depthImageFrame.CopyPixelDataTo(pixelData);
//this.image1.Source = BitmapSource.Create(depthImageFrame.Width, depthImageFrame.Height, 96, 96, PixelFormats.Gray16, null, pixelData, depthImageFrame.Width * depthImageFrame.BytesPerPixel);

this.depthFrame32 = new byte[depthImageFrame.Width * depthImageFrame.Height * 4];
this.depthFrame32 = ConvertDepthFrame(pixelData, ((KinectSensor)sender).DepthStream);

this.image1.Source = BitmapSource.Create(depthImageFrame.Width, depthImageFrame.Height, 96, 96, PixelFormats.Bgr32, null, depthFrame32, depthImageFrame.Width * 4);
}
}
}

这是个事件处理函数
请问第三行代码DepthImageFrame depthImageFrame = e.OpenDepthImageFrame()是啥意思?为啥不是DepthImageFrame depthImageFrame = new DepthImageFrame()?
其中DepthImageFrame是个类,我一直按F12,发现它最终继承于一个接口,但我还没学到接口。

然后,我查看OpenDepthImageFrame()的定义,发现最终有如下代码
namespace Microsoft.Kinect
{
// 摘要:
// Arguments for the DepthFrameReady events.
public sealed class DepthImageFrameReadyEventArgs : EventArgs
{
// 摘要:
// Container for one frame's worth of depth sensor image data Can return null
// if the data is not available. Upon success, returns the DepthImageFrame
// corresponding to this event, which must be Disposed.
//
// 返回结果:
// An a new depth image frame.
public DepthImageFrame OpenDepthImageFrame();
}
}


请问这里的 public DepthImageFrame OpenDepthImageFrame();又该怎么理解?为啥类后面跟了一个方法?
...全文
91 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
可爱的芒果酱 2015-05-11
  • 打赏
  • 举报
回复
感谢上面两位的回答,我好像还是不是太懂,我再研究下
moonwrite 2015-05-11
  • 打赏
  • 举报
回复
public interface 咬 public class 猫 : 咬 public class 宠物店 { public 咬 Creat()//百度一下工厂模式 { return new 猫() } }
江南小鱼 2015-05-11
  • 打赏
  • 举报
回复
请问这里的 public DepthImageFrame OpenDepthImageFrame();又该怎么理解?为啥类后面跟了一个方法? DepthImageFrameReadyEventArgs是一个密封类,自定义事件,提供成员OpenDepthImageFrame,在调用事件的时候,由调用方传递OpenDepthImageFrame对象过来。 请问第三行代码DepthImageFrame depthImageFrame = e.OpenDepthImageFrame()是啥意思?为啥不是DepthImageFrame depthImageFrame = new DepthImageFrame()? e.OpenDepthImageFrame是获取触发事件的主题实例化的DepthImageFrame对象,这个的相关属性(Width、Height)等事件触发时已赋值 而你直接new进行实例化,Width、Height的值没有触发事件的主题的值

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧