비디오 스트림에 오버레이 된 이미지를 표시하기 위해 ColorBasic Kinect 예제를 수정합니다. 그래서 내가 한 일은 투명 배경이 인 이미지 (현재 GIF이지만 변경 될 수 있음)을로드하고 표시된 비트 맵에 쓰는 것입니다.WriteableBitmap을 사용하여 버퍼 크기가 부족합니까?
내가 얻는 오류는 내가 쓰고있는 버퍼가 너무 작습니다.
실제 오류 (XAML/C#/Kinect의 완전한 초보자)가 표시되지 않지만 WriteableBitmap은 1920x1080이며 복사 할 비트 맵이 200x200이므로이 오류가 발생합니다. ? 나는 투명한 배경이 어떤 해로울 수 있는지를 볼 수는 없지만, 그게 의심 스럽다. ...
마지막 WritePixels가 없으면 코드가 작동하고 웹캠의 출력을 볼 수있다. 내 코드는 다음과 같습니다.
오버레이 이미지 :
public BitmapImage overlay = new BitmapImage(new Uri("C:\\users\\user\\desktop\\something.gif"));
내 아주 작은 수정을 넥트의 웹캠 (기본 예 ColorBasic 참조)를 표시하는 콜백 함수 :
private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
// ColorFrame is IDisposable
using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
{
if (colorFrame != null)
{
FrameDescription colorFrameDescription = colorFrame.FrameDescription;
using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer())
{
this.colorBitmap.Lock();
// verify data and write the new color frame data to the display bitmap
if ((colorFrameDescription.Width == this.colorBitmap.PixelWidth) && (colorFrameDescription.Height == this.colorBitmap.PixelHeight))
{
colorFrame.CopyConvertedFrameDataToIntPtr(
this.colorBitmap.BackBuffer,
(uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4),
ColorImageFormat.Bgra);
this.colorBitmap.AddDirtyRect(new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight));
}
if(this.overlay != null)
{
// Calculate stride of source
int stride = overlay.PixelWidth * (overlay.Format.BitsPerPixel/8);
// Create data array to hold source pixel data
byte[] data = new byte[stride * overlay.PixelHeight];
// Copy source image pixels to the data array
overlay.CopyPixels(data, stride, 0);
this.colorBitmap.WritePixels(new Int32Rect(0, 0, overlay.PixelWidth, overlay.PixelHeight), data, stride, 0);
}
this.colorBitmap.Unlock();
}
}
}
}