Пример #1
0
        /// <summary>
        /// Deaktiviert die Bildüberlagerung.
        /// </summary>
        public void ClearOverlayBitmap()
        {
            // Create structure
            var param = new VMRAlphaBitmap { Flags = VMRAlphaBitmapFlags.Disable };

            // Forward
            using (var vmr = VMR.MarshalToManaged())
                ((IVMRMixerBitmap) vmr.Object).SetAlphaBitmap( ref param );
        }
Пример #2
0
        /// <summary>
        /// Aktiviert die Bildüberlagerung.
        /// </summary>
        /// <param name="bitmap">Die gewünschte Überlagerung.</param>
        /// <param name="left">Die linke Seite.</param>
        /// <param name="top">Die obere Seite.</param>
        /// <param name="right">Die rechte Seite.</param>
        /// <param name="bottom">Die untere Seite.</param>
        /// <param name="alpha">Der Transparenzfaktor.</param>
        /// <param name="sourceColor">Optional der Transparenzschlüssel.</param>
        public void SetOverlayBitmap( Bitmap bitmap, double left, double top, double right, double bottom, double alpha, Color? sourceColor )
        {
            // Attach to video window device context
            using (var self = Graphics.FromHwnd( m_VideoWindow.Handle ))
            {
                // Get the device context
                IntPtr originalHDC = self.GetHdc();
                try
                {
                    // Create the HDC
                    IntPtr compat = CreateCompatibleDC( originalHDC );
                    try
                    {
                        // Create the memory device context
                        using (var inMem = Graphics.FromHdc( compat ))
                        {
                            // Get the device context
                            IntPtr memoryHDC = inMem.GetHdc();
                            try
                            {
                                // Get the bitmap
                                IntPtr bmp = bitmap.GetHbitmap();
                                try
                                {
                                    // Select the bitmap into it
                                    IntPtr prev = SelectObject( memoryHDC, bmp );
                                    try
                                    {
                                        // Create structure
                                        var param =
                                            new VMRAlphaBitmap
                                            {
                                                Target = { Left = (float) left, Top = (float) top, Bottom = (float) bottom, Right = (float) right, },
                                                Source = { Right = bitmap.Width, Bottom = bitmap.Height },
                                                Flags = VMRAlphaBitmapFlags.DeviceHandle,
                                                DeviceHandle = memoryHDC,
                                                Alpha = (float) alpha,
                                            };

                                        // Set the source color
                                        if (sourceColor.HasValue)
                                        {
                                            // Finish
                                            param.Flags |= VMRAlphaBitmapFlags.SourceColorKey;
                                            param.SourceColorKey = (uint) sourceColor.Value.ToArgb();
                                        }

                                        // Activate
                                        using (var vmr = VMR.MarshalToManaged())
                                            ((IVMRMixerBitmap) vmr.Object).SetAlphaBitmap( ref param );
                                    }
                                    finally
                                    {
                                        // Restore
                                        SelectObject( memoryHDC, prev );
                                    }
                                }
                                finally
                                {
                                    // Cleanup
                                    DeleteObject( bmp );
                                }
                            }
                            finally
                            {
                                // Release resources
                                inMem.ReleaseHdc();
                            }
                        }
                    }
                    finally
                    {
                        // Release HDC
                        DeleteDC( compat );
                    }
                }
                finally
                {
                    // Release resources
                    self.ReleaseHdc();
                }
            }
        }