I am trying to save a kinect depth sensor image to a png file. I tried to take this with my RGB camera and it didn’t have any problems. Is there something that I missed out on?
P.S. I am using Kinect ToolKit’s functions for both rgb and depth image display.
WriteableBitmap depthBitmap;
DepthStreamManager dsm;
dsm = new DepthStreamManager();
kinect.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
kinect.DepthFrameReady += kinect_DepthFrameReady;
depthBitmap = new WriteableBitmap(kinect.DepthStream.FrameWidth,this.kinect.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Gray16, null);
private string TakeImage(int x)
{
if (x == 0)
{
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(this.depthBitmap));
string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string path = System.IO.Path.Combine(myPhotos, "Image 1.png");
try
{
using (FileStream fs = new FileStream(path, FileMode.Create))
{
encoder.Save(fs);
}
}
catch (IOException details)
{
Console.Write(details.ToString());
}
if (path == null)
return "Image was not taken.";
else
return path;
}}
Solution to my own problem:
Using Kinect’s ToolKit, they actually supplied a writable bitmap function that allows me to grab the ColorStreamManager or DepthStreamManager’s WritableBitmap out. My error previously was that since I wasn’t using Kinect’s innate display methods, the writeablebitmap will definitely be empty. This is my fixed codes.