private void InitOpenNI()
{
// ContextとImageGeneratorの作成
ScriptNode node;
context = Context.CreateFromXmlFile( "SamplesConfig.xml", out node );
context.GlobalMirror = false;
image = context.FindExistingNode( NodeType.Image ) as ImageGenerator;
// 画像更新のためのスレッドを作成
shouldRun = true;
readerThread = new Thread( new ThreadStart( () =>
{
while ( shouldRun ) {
context.WaitAndUpdateAll();
ImageMetaData imageMD = image.GetMetaData();
// ImageMetaDataをBitmapSourceに変換する(unsafeにしなくてもOK!!)
this.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action( () =>
{
imageOpenNI.Source = BitmapSource.Create( imageMD.XRes, imageMD.YRes,
96, 96, PixelFormats.Rgb24, null, imageMD.ImageMapPtr,
imageMD.DataSize, imageMD.XRes * imageMD.BytesPerPixel );
} ) );
}
} ) );
readerThread.Start();
}