问题
I have some problem with the kinect. when I try to get color Image from the event: Sensor_AllFramesReady everything is ok. example:
using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) {
//save image for print
if (colorFrame == null) {
return;
}
byte[] colorData = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(colorData);
int averagedImage = colorFrame.Width * PixelFormats.Bgr32.BitsPerPixel / 8;
int stride = colorFrame.Width * 4;
pictureBitmap = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, colorData, stride);
}
But when I try to do the same code outside the event with
using (ColorImageFrame Image = Sensor.ColorStream.OpenNextFrame(10)) {
}
I get error : "This API cannot be called when an event listener has been set"
I try to remove the event before calling this function but this don't change anything
回答1:
You have to choice, event handler or poll method. You can use the event and save the last frame to use it some else place.
来源:https://stackoverflow.com/questions/12210931/get-color-image-not-in-the-frame-ready-event