您可以在界面上放置一个Image控件,然后将Kinect的数据展现到上面,然后保存为图片即可。
<Window x:Class="KinectApplicationFoundation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ColorImageStreamFromKinect" Height="350" Width="525">
<Grid>
<Image x:Name="ColorImageElement"></Image>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
<Button Content="Take Picture" Click="TakePictureButton_Click" />
</StackPanel>
</Grid>
</Window>
private void TakePictureButton_Click(object sender, RoutedEventArgs e)
{
String fileName = "snapshot.jpg";
if (File.Exists(fileName))
{
File.Delete(fileName);
}
using (FileStream savedSnapshot=new FileStream(fileName,FileMode.CreateNew))
{
BitmapSource image =(BitmapSource) ColorImageElement.Source;
JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder();
jpgEncoder.QualityLevel = 70;
jpgEncoder.Frames.Add(BitmapFrame.Create(image));
jpgEncoder.Save(savedSnapshot);
savedSnapshot.Flush();
savedSnapshot.Close();
savedSnapshot.Dispose();
}
}