Example #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 VMR9AlphaBitmap();
            alphaBitmap.dwFlags      = VMR9AlphaBitmapFlags.hDC | VMR9AlphaBitmapFlags.SrcColorKey | VMR9AlphaBitmapFlags.FilterMode;
            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(colorKey);
            alphaBitmap.dwFilterMode = VMRMixerPrefs.BiLinearFiltering;

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

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

            Debug.Assert(hr == 0, "IVMRMixerBitmap9.SetAlphaBitmap");
        }
Example #2
0
        private void SetMixerSettings()
        {
            int             hr = 0;
            VMR9AlphaBitmap alphaBmp;

            if (!mixerEnabled) // Did the user disable the bitmap ?
            {
                // Get current Alpha Bitmap Parameters
                hr = mixerBitmap.GetAlphaBitmapParameters(out alphaBmp);
                DsError.ThrowExceptionForHR(hr);

                // Disable them
                alphaBmp.dwFlags = VMR9AlphaBitmapFlags.Disable;

                // Update the Alpha Bitmap Parameters
                hr = mixerBitmap.UpdateAlphaBitmapParameters(ref alphaBmp);
                DsError.ThrowExceptionForHR(hr);

                return;
            }

            if (usingGDI)
            {
                // Old school GDI stuff...
                Graphics g       = Graphics.FromImage(colorKeyBitmap);
                IntPtr   hdc     = g.GetHdc();
                IntPtr   memDC   = NativeMethodes.CreateCompatibleDC(hdc);
                IntPtr   hBitmap = colorKeyBitmap.GetHbitmap();
                NativeMethodes.SelectObject(memDC, hBitmap);

                // Set Alpha Bitmap Parameters for using a GDI DC
                alphaBmp              = new VMR9AlphaBitmap();
                alphaBmp.dwFlags      = VMR9AlphaBitmapFlags.hDC | VMR9AlphaBitmapFlags.SrcColorKey | VMR9AlphaBitmapFlags.FilterMode;
                alphaBmp.hdc          = memDC;
                alphaBmp.rSrc         = new DsRect(0, 0, colorKeyBitmap.Size.Width, colorKeyBitmap.Size.Height);
                alphaBmp.rDest        = GetDestRectangle();
                alphaBmp.clrSrcKey    = ColorTranslator.ToWin32(colorKey);
                alphaBmp.dwFilterMode = VMRMixerPrefs.PointFiltering;
                alphaBmp.fAlpha       = 0.75f;

                // Set Alpha Bitmap Parameters
                hr = mixerBitmap.SetAlphaBitmap(ref alphaBmp);
                DsError.ThrowExceptionForHR(hr);

                // Release GDI handles
                NativeMethodes.DeleteObject(hBitmap);
                NativeMethodes.DeleteDC(memDC);
                g.ReleaseHdc(hdc);
                g.Dispose();
            }
            else // Using a Direct3D surface
            {
                // Set Alpha Bitmap Parameters for using a Direct3D surface
                alphaBmp         = new VMR9AlphaBitmap();
                alphaBmp.dwFlags = VMR9AlphaBitmapFlags.EntireDDS;
                alphaBmp.pDDS    = unmanagedSurface;
                alphaBmp.rDest   = GetDestRectangle();
                alphaBmp.fAlpha  = 1.0f;
                // Note : Alpha values from the bitmap are cumulative with the fAlpha parameter.
                // Example : texel alpha = 128 (50%) & fAlpha = 0.5f (50%) = effective alpha : 64 (25%)

                // Set Alpha Bitmap Parameters
                hr = mixerBitmap.SetAlphaBitmap(ref alphaBmp);
                DsError.ThrowExceptionForHR(hr);
            }
        }