2014-11-06 93 views
0

任何人都知道,如果可能的話,如何降低顏色流的kinect框架分辨率?因爲全高清尺寸是太高了,我scope.Thanks 我已經找到了全高清幀此代碼:Kinect v2 for windows:在c中調整顏色框架的大小#

private BitmapSource ToBitmap(ColorFrame frame) 
    { 
     int width = frame.FrameDescription.Width; 
     int height = frame.FrameDescription.Height; 
     PixelFormat format = PixelFormats.Bgr32; 

     byte[] pixels = new byte[width * height * ((PixelFormats.Bgr32.BitsPerPixel + 7)/8)]; 

     if (frame.RawColorImageFormat == ColorImageFormat.Bgra) 
     { 
      frame.CopyRawFrameDataToArray(pixels); 
     } 
     else 
     { 
      frame.CopyConvertedFrameDataToArray(pixels, ColorImageFormat.Bgra); 
     } 

     int stride = width * format.BitsPerPixel/8; 



     return BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride); 


    } 
+0

什麼參考您包括在內,以便使用「BitmapSource」和「PixelFormats」和「BitsPerPixel」? – ThunderWiring 2016-09-27 08:31:43

+0

對不起,但我不再有這個項目,但我認爲這些都在System.Windows.media – luca 2016-09-27 15:22:02

回答

0

我已經解決了在結尾添加該代碼

BitmapSource bitmap= BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride); 
ScaleTransform scale=new ScaleTransform((Width/bitmap.PixelWidth),(Height/bitmap.PixelHeight)); 
TransformedBitmap tbBitmap = new TransformedBitmap(bitmap, scale); 

return tbBitmap; 

所以完整的方法是:

private BitmapSource ToBitmap(ColorFrame frame) 
    { 
     int width = frame.FrameDescription.Width; 
     int height = frame.FrameDescription.Height; 
     PixelFormat format = PixelFormats.Bgr32; 

     byte[] pixels = new byte[width * height * ((PixelFormats.Bgr32.BitsPerPixel + 7)/8)]; 

     if (frame.RawColorImageFormat == ColorImageFormat.Bgra) 
     { 
      frame.CopyRawFrameDataToArray(pixels); 
     } 
     else 
     { 
      frame.CopyConvertedFrameDataToArray(pixels, ColorImageFormat.Bgra); 
     } 

     int stride = width * format.BitsPerPixel/8; 
     BitmapSource bitmap= BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride); 
     ScaleTransform scale=new ScaleTransform((640.0/bitmap.PixelWidth),(480.0/bitmap.PixelHeight)); 
     TransformedBitmap tbBitmap = new TransformedBitmap(bitmap, scale); 

     return tbBitmap; 
    } 
相關問題