2014-11-18 6 views
2

비디오 스트림에 오버레이 된 이미지를 표시하기 위해 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(); 
      } 
     } 
    } 
} 

답변

2

귀하의 overlay.Format.BitsPerPixel/8 일이 될 것이다 (왜냐하면 그것은 gif이기는하지만) gif가 아닌 무언가, 아마도 BGRA (32 비트)에 복사하려고합니다. 따라서 크기면에서 큰 차이가 있습니다 (4x).


.WritePixels는 과거 오버레이의 보폭 값을 (이뿐만 아니라 이상한 문제가 발생할 수 있습니다)을 대상 버퍼의 보폭 값에 걸리지 만한다.


그리고 마지막으로, 그것은 100 % 오버레이는 실제로 "오버레이"무엇이든, 그것을 대체 할 것이다 부드럽게했다하더라도 - 나는 당신의 코드에서 수학을 굽힘 알파가 표시되지 않기 때문에.

.gif를 .png (32 비트)로 전환하여 도움이되는지 확인하십시오.

또한 AlphaBltMerge 유형 코드를 찾는 경우 : 전체 내용을 여기에 썼습니다. 매우 이해하기 쉽습니다.


Merge 2 - 32bit Images with Alpha Channels

관련 문제