public void TestGetAlphaBitmapParameters() { int hr = 0; VMR9AlphaBitmap tmp; hr = mixerBitmap.GetAlphaBitmapParameters(out tmp); DsError.ThrowExceptionForHR(hr); // We could test other fields but this one is significative... Debug.Assert(tmp.clrSrcKey == ColorTranslator.ToWin32(colorKey), "IVMRMixerBitmap9.GetAlphaBitmapParameters"); }
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); } }