This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WriteableBitmap colorBitmap; | |
byte[] ColorImagePixelData ; | |
Int32Rect colorImageBitmapRect; | |
FrameDescription myColorFrameDescripton; | |
public MainWindow(){ | |
InitializeComponent(); | |
KinectSensor kinect = KinectSensor.GetDefault(); | |
if (kinect != null){ | |
ColorFrameReader colorframereader = kinect.ColorFrameSource.OpenReader(); | |
myColorFrameDescripton = kinect.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); | |
ColorImagePixelData = new byte[myColorFrameDescripton.Width * myColorFrameDescripton.Height * myColorFrameDescripton.BytesPerPixel]; | |
colorBitmap = new WriteableBitmap(myColorFrameDescripton.Width, myColorFrameDescripton.Height, 96.0, 96.0, PixelFormats.Bgr32, null); | |
colorframereader.FrameArrived+=colorframereader_FrameArrived; | |
kinect.Open(); | |
} | |
} | |
void colorframereader_FrameArrived(object sender, ColorFrameArrivedEventArgs e){ | |
using( ColorFrame myColorFrame= e.FrameReference.AcquireFrame()){ | |
if(myColorFrame!=null){ | |
myColorFrame.CopyConvertedFrameDataToArray(ColorImagePixelData, ColorImageFormat.Bgra); | |
colorImageBitmapRect = new Int32Rect(0, 0, myColorFrameDescripton.Width, myColorFrameDescripton.Height); | |
image1.Source = BitmapSource.Create(myColorFrameDescripton.Width, myColorFrameDescripton.Height, 96, 96,PixelFormats.Bgra32, null, ColorImagePixelData, myColorFrameDescripton.Width * (int)myColorFrameDescripton.BytesPerPixel); | |
} | |
GC.Collect(); //Win8.1のバグ?らしいのでこのおまじないを書いておくこと } | |
} |
0 件のコメント:
コメントを投稿