Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将深度帧另存为PNG 16文件-Kinect SDK_C#_Wpf_Sdk_Kinect_Depth - Fatal编程技术网

C# 将深度帧另存为PNG 16文件-Kinect SDK

C# 将深度帧另存为PNG 16文件-Kinect SDK,c#,wpf,sdk,kinect,depth,C#,Wpf,Sdk,Kinect,Depth,我需要将深度帧保存为灰色PNG 16图像。 我只知道如何将它们保存为32bgr图像。 这是我的密码: private byte[] depthFrame32; using (DepthImageFrame imageFrame = e.OpenDepthImageFrame()) { if (imageFrame != null) { int stride = imageFrame.Width * 4; BitmapSource bmp = Bitma

我需要将深度帧保存为灰色PNG 16图像。 我只知道如何将它们保存为32bgr图像。 这是我的密码:

private byte[] depthFrame32;
using (DepthImageFrame imageFrame = e.OpenDepthImageFrame())
{
   if (imageFrame != null)
   {
        int stride = imageFrame.Width * 4;
        BitmapSource bmp = BitmapSource.Create(imageFrame.Width, imageFrame.Height,
            96, 96, PixelFormats.Bgr32, null, this.depthFrame32, stride);



         using (var fileStream = new FileStream(full_path, FileMode.Create))
         {
              BitmapEncoder encoder = new PngBitmapEncoder();
              encoder.Frames.Add(BitmapFrame.Create(bmp));
              encoder.Save(fileStream);
         }
   }
}

提前感谢

不确定您的
depthFrame32
数组在哪里填充了图像数据

无论如何,您说过您知道如何将深度帧保存为BGR32位图。然后,您可以始终从原始位图创建
FormatConvertedBitmap
,并保存该位图:

...
var gray16Bitmap = new FormatConvertedBitmap(bmp, PixelFormats.Gray16, null, 0d);

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(gray16Bitmap));

using (var fileStream = new FileStream(full_path, FileMode.Create))
{
    encoder.Save(fileStream);
}

假设您已经有16位灰度数据(例如,从
DepthImageFrame.CopyPixelDataTo
的转换结果),您当然也可以直接创建如下位图源:

var stride = imageFrame.Width * 2;
var bmp = BitmapSource.Create(imageFrame.Width, imageFrame.Height,
    96, 96, PixelFormats.Gray16, null, grayScaleData, stride);