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 VMR9AlphaBitmap(); alphaBitmap.dwFlags = VMR9AlphaBitmapFlags.SrcColorKey | VMR9AlphaBitmapFlags.FilterMode; 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(colorKey); alphaBitmap.dwFilterMode = VMRMixerPrefs.BiLinearFiltering; hr = mixerBitmap.UpdateAlphaBitmapParameters(ref alphaBitmap); DsError.ThrowExceptionForHR(hr); Debug.Assert(hr == 0, "IVMRMixerBitmap9.UpdateAlphaBitmapParameters"); }
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); } }