2011-09-16 7 views
3

에 카메라 이미지를 렌더링 내가 uEye 카메라를 가지고와 나는 1000MS 간격으로 이미지의 스냅 샷을하고 난 노력하고 있어요 그래서WPF의 Image 컨트롤

Bitmap MyBitmap; 

// get geometry of uEye image buffer 

int width = 0, height = 0, bitspp = 0, pitch = 0, bytespp = 0; 

long imagesize = 0; 

m_uEye.InquireImageMem(m_pCurMem, GetImageID(m_pCurMem), ref width, ref height, ref bitspp, ref pitch); 

bytespp = (bitspp + 1)/8; 

imagesize = width * height * bytespp; // image size in bytes 

// bulit a system bitmap 
MyBitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb); 

// fill the system bitmap with the image data from the uEye SDK buffer 
BitmapData bd = MyBitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); 
m_uEye.CopyImageMem(m_pCurMem, GetImageID(m_pCurMem), bd.Scan0); 
MyBitmap.UnlockBits(bd); 

같은 WPF Image 제어에서 그들을 렌더링 할 이 비트 맵을 Image 컨트롤에 1 초의 속도로 넣습니다. BitmapImage 컨트롤에 나타나게하고 가능한 한 최소한의 메모리 사용량을 남겨두면 좋은 프로그래머가 될 것입니다. :) 여기

답변

4

(가 로딩 CPU없이 200fps에서 일하는 나를 위해 (약 5 %)) 우리가하는 방법 :

private WriteableBitmap PrepareForRendering(VideoBuffer videoBuffer) { 
     PixelFormat pixelFormat; 
     if (videoBuffer.pixelFormat == PixFrmt.rgb24) { 
      pixelFormat = PixelFormats.Rgb24; 
     } else if (videoBuffer.pixelFormat == PixFrmt.bgra32) { 
      pixelFormat = PixelFormats.Bgra32; 
     } else if (videoBuffer.pixelFormat == PixFrmt.bgr24) { 
      pixelFormat = PixelFormats.Bgr24; 
     } else { 
      throw new Exception("unsupported pixel format"); 
     } 
     var bitmap = new WriteableBitmap(
      videoBuffer.width, videoBuffer.height, 
      96, 96, 
      pixelFormat, null 
     ); 
     _imgVIew.Source = bitmap; 
     return bitmap; 
    } 

    private void DrawFrame(WriteableBitmap bitmap, VideoBuffer videoBuffer, double averangeFps) { 
     VerifyAccess(); 
     if (isPaused) { 
      return; 
     } 

     bitmap.Lock(); 
     try { 
      using (var ptr = videoBuffer.Lock()) { 
       bitmap.WritePixels(
        new Int32Rect(0, 0, videoBuffer.width, videoBuffer.height), 
        ptr.value, videoBuffer.size, videoBuffer.stride, 
        0, 0 
       ); 
      } 
     } finally { 
      bitmap.Unlock(); 
     } 
     fpsCaption.Text = averangeFps.ToString("F1"); 
    }