Rendering out camera images to a WPF Image control

前端 未结 1 671
囚心锁ツ
囚心锁ツ 2021-01-03 10:32

I have a uEye camera and I take snapshots of images at a 1000ms interval and I want to render them in a WPF Image Control like so

 Bitmap MyBitmap;

// get          


        
相关标签:
1条回答
  • 2021-01-03 11:24

    Here the way we do (for me it works at 200fps without loading CPU (about 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");
        }
    
    0 讨论(0)
提交回复
热议问题