如何将Microsoft.Kinect.ColorImageFormat转换为System.Windows.Media.PixelFormat? [英] How to convert Microsoft.Kinect.ColorImageFormat to System.Windows.Media.PixelFormat?

查看:113
本文介绍了如何将Microsoft.Kinect.ColorImageFormat转换为System.Windows.Media.PixelFormat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行Kinect编程,当我启用颜色流时,我定义为使用Bayer 30帧/秒格式(ColorImageFormat.RawBayerResolution640x480Fps30)。



渲染图像时,我使用以下代码:

I am doing Kinect programming and when I enable the color stream, I defined to use Bayer 30 frames per second format (ColorImageFormat.RawBayerResolution640x480Fps30).

When rendering the image, I use the following code:

PixelFormat format = PixelFormats.Bgr32;

// Bitmap source to write to.
WriteableBitmap src = new WriteableBitmap((int)_kinectSensor.ColorStream.FrameWidth, (int)_kinectSensor.ColorStream.FrameHeight, 96, 96, format, null);

// Stride for image.
var stride = (int)_kinectSensor.ColorStream.FrameWidth * format.BitsPerPixel / 8;

// Write pixels to bitmap source.
src.WritePixels(new Int32Rect(0, 0, (int)imgPic.Width, (int)imgPic.Height), rawBayerPixels, stride, 0);

// Set XAML image source = Bitmap source.
imgPic.Source = src;



如何在没有硬编码的情况下根据所选的ColorImageFormat锻炼PixelFormat?那么将一个枚举转换为另一个?



提前致谢!


How do I workout the PixelFormat without hardcoding as above, based on the selected ColorImageFormat? So convert one enum to the other?

Thanks in advance!

推荐答案

您不能直接将一个枚举转换为另一个枚举但是您可以使用它们基于整数值作为解决方法的事实。如果枚举值相同,你可以用IsDefined做一些事情来判断给定的值是否与另一个值匹配然后返回。



我还没有看看那些特定的枚举,知道它们如何匹配,但很可能你必须手动匹配它们。我建议一个函数返回所需的枚举类型,并将源类型作为参数。也许你可以使用System.Enum上的一些函数进行一些动态匹配,但更糟糕的情况是,你可以编写一个switch语句来为另一个返回一个值。



无论如何,我会检查枚举类上的MSDN文档。那里有很多辅助函数可以帮助你。
You can't directly cast one enum to another but you can use the fact that they are based on integer values as a work around. If the enumeration VALUES are the same, you could probably do something with IsDefined to figure out if a given values matches another one and then return that.

I haven't looked at those particular enums to know how they match up but more than likely you are going to have to "manually" match them up. I would suggest a function that returns the desired enum type and takes the source type as a parameter. Maybe you can use some of the functions on System.Enum to do some dynamic matching but even worse case, you could write a switch statement to return one value for another.

At any rate, I would check the MSDN docs on the enum class. There are lots of helper functions there that may assist you.


这篇关于如何将Microsoft.Kinect.ColorImageFormat转换为System.Windows.Media.PixelFormat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆