//private IntPtr m_handle = IntPtr.Zero; //private int m_videoWidth; //private int m_videoHeight; //private int m_stride; protected void WpfUpdateVideoSize() { if (this.videoRenderer is ISampleGrabber) { try { ISampleGrabber sampGrabber = this.videoRenderer as ISampleGrabber; // Get the media type from the SampleGrabber AMMediaType media = new AMMediaType(); int hr = sampGrabber.GetConnectedMediaType(media); DsError.ThrowExceptionForHR(hr); if ((media.formatType != FormatType.VideoInfo) || (media.formatPtr == IntPtr.Zero)) { throw new NotSupportedException("Unknown Grabber Media Format"); } // Grab the size info VideoInfoHeader videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader)); int videoWidth = videoInfoHeader.BmiHeader.Width; int videoHeight = videoInfoHeader.BmiHeader.Height; int stride = videoWidth * (videoInfoHeader.BmiHeader.BitCount / 8); DsUtils.FreeAMMediaType(media); media = null; int bytePerPixel = 4; // These are 'dummy' pixels only used to create our bitmap // further editing after bitmap creation of these pixels does nothing, // that is what this hack is for byte[] frameBuffer = new byte[videoWidth * videoHeight * bytePerPixel]; //Create a new bitmap source BitmapSource bitmapSource = BitmapSource.Create(videoWidth, videoHeight, 96, 96, PixelFormats.Bgr32, null, frameBuffer, videoWidth * bytePerPixel); this.hostingControl.WPFImage.Source = bitmapSource; lock (this.hostingControl.WPFImage) { this.wpfBitmapBuffer = new WPFUtil.BitmapBuffer(bitmapSource); } } catch (Exception) { } } }
protected void WPFStop() { if (this.hostingControl != null && this.hostingControl.WPFImage != null) { lock (this.hostingControl.WPFImage) { this.wpfBitmapBuffer = null; } } }