예제 #1
0
        public void TestSetAlphaBitmap()
        {
            int hr = 0;

            // GDI Stuff
            IntPtr hdc     = g.GetHdc();
            IntPtr memDC   = CreateCompatibleDC(hdc);
            IntPtr hBirmap = bmp.GetHbitmap();

            SelectObject(memDC, hBirmap);

            alphaBitmap           = new VMRAlphaBitmap();
            alphaBitmap.dwFlags   = VMRBitmap.Hdc | VMRBitmap.SRCColorKey;
            alphaBitmap.hdc       = memDC;
            alphaBitmap.pDDS      = IntPtr.Zero;
            alphaBitmap.fAlpha    = 0.5f;
            alphaBitmap.rSrc      = new DsRect(0, 0, 255, 255); // SetAlphaBitmap only accept the full size
            alphaBitmap.rDest     = new NormalizedRect(0.0f, 0.0f, 1.0f, 1.0f);
            alphaBitmap.clrSrcKey = ColorTranslator.ToWin32(Color.Magenta);

            hr = mixerBitmap.SetAlphaBitmap(ref alphaBitmap);
            DsError.ThrowExceptionForHR(hr);

            DeleteObject(hBirmap);
            DeleteDC(memDC);
            g.ReleaseHdc(hdc);

            Debug.Assert(hr == 0, "IVMRMixerBitmap.SetAlphaBitmap");
        }
예제 #2
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);
        }
예제 #3
0
        public void TestUpdateAlphaBitmapParameters()
        {
            int hr = 0;

            // show the bitmap half smaller in the middle of the window
            // We don't change the image so no need to play again with GDI
            alphaBitmap           = new VMRAlphaBitmap();
            alphaBitmap.dwFlags   = VMRBitmap.SRCColorKey;
            alphaBitmap.hdc       = IntPtr.Zero;
            alphaBitmap.pDDS      = IntPtr.Zero;
            alphaBitmap.fAlpha    = 0.5f;
            alphaBitmap.rSrc      = new DsRect(0, 0, 255, 255);
            alphaBitmap.rDest     = new NormalizedRect(0.25f, 0.25f, 0.75f, 0.75f);
            alphaBitmap.clrSrcKey = ColorTranslator.ToWin32(Color.Magenta);

            hr = mixerBitmap.UpdateAlphaBitmapParameters(ref alphaBitmap);
            DsError.ThrowExceptionForHR(hr);

            Debug.Assert(hr == 0, "IVMRMixerBitmap.UpdateAlphaBitmapParameters");
        }
예제 #4
0
        //public bool IsVMR7Connected

        public bool SaveBitmap(Bitmap bitmap, bool show, bool transparent, float alphaValue)
        {
            if (!vmr7intialized)
            {
                return(true);
            }
            if (GUIGraphicsContext.Vmr9Active)
            {
                return(true);
            }
            if (MixerBitmapInterface == null)
            {
                return(false);
            }


            if (VMR7Filter != null)
            {
                int hr = 0;

                VMRAlphaBitmap bmp = new VMRAlphaBitmap();

                if (show == true)
                {
                    if (bitmap != null)
                    {
//						System.Drawing.ImageConverter conv=new ImageConverter();
//						byte[] imgComp=new byte[0];
//						imgComp=(byte[])conv.ConvertTo(bitmap,imgComp.GetType());
                        //ulong crcVal=crc.calc(imgComp);
//						if(crcVal==m_oldSavedBitmapCRC)
//							return false;

//						m_oldSavedBitmapCRC=crcVal;

                        using (Bitmap n = new Bitmap(bitmap.Width, bitmap.Height))
                        {
                            using (Graphics g = Graphics.FromImage(n))
                            {
                                g.Clear(Color.Black);
                                g.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height);
                                IntPtr handle1   = g.GetHdc();
                                IntPtr hdc       = Win32API.CreateCompatibleDC(handle1);
                                IntPtr oldBitmap = Win32API.SelectObject(hdc, n.GetHbitmap());
                                bmp.dwFlags      = (VMRBitmap)((int)VMRBitmap.Hdc + (int)VMRBitmap.SRCColorKey);
                                bmp.clrSrcKey    = 0;
                                bmp.pDDS         = IntPtr.Zero;
                                bmp.hdc          = hdc;
                                bmp.rSrc         = new DsRect();
                                bmp.rSrc.top     = 0;
                                bmp.rSrc.left    = 0;
                                bmp.rSrc.right   = bitmap.Width;
                                bmp.rSrc.bottom  = bitmap.Height;
                                bmp.rDest        = new NormalizedRect();
                                bmp.rDest.top    = 0.0f;
                                bmp.rDest.left   = 0.0f;
                                bmp.rDest.bottom = 1.0f;
                                bmp.rDest.right  = 1.0f;
                                bmp.fAlpha       = alphaValue;
                                //Log.Info("SaveVMR7Bitmap() called");

                                hr = g_vmr7.MixerBitmapInterface.SetAlphaBitmap(ref bmp);
                                //g.ReleaseHdc(ptrSrc);
                                Win32API.DeleteDC(hdc);
                                g.ReleaseHdc(handle1);
                                if (hr != 0)
                                {
                                    Log.Info("SaveVMR7Bitmap() failed: error 0x{0:X} on SetAlphaBitmap()", hr);
                                    return(false);
                                }
                            }
                        }
                    }
                }
                else
                {
                    bmp.dwFlags      = VMRBitmap.Disable;
                    bmp.clrSrcKey    = 0;
                    bmp.hdc          = IntPtr.Zero;
                    bmp.rDest        = new NormalizedRect();
                    bmp.rDest.top    = 0.0f;
                    bmp.rDest.left   = 0.0f;
                    bmp.rDest.bottom = 1.0f;
                    bmp.rDest.right  = 1.0f;
                    bmp.fAlpha       = alphaValue;
                    //Log.Info("SaveVMR7Bitmap() called");
                    hr = g_vmr7.MixerBitmapInterface.SetAlphaBitmap(ref bmp);
                    if (hr != 0)
                    {
                        Log.Info("SaveVMR7Bitmap() failed: error {0:X} on SetAlphaBitmap()", hr);
                        return(false);
                    }
                }
                // dispose
                return(true);
            }
            return(false);
        }
예제 #5
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();
                }
            }
        }