예제 #1
0
        private void Test()
        {
            MFVideoAlphaBitmap ab = new MFVideoAlphaBitmap();
            MFVideoAlphaBitmapParams abp = new MFVideoAlphaBitmapParams();
            MFVideoAlphaBitmapParams abp2 = new MFVideoAlphaBitmapParams();
            Bitmap bm = new Bitmap(@"C:\Windows\Web\Wallpaper\Windows\img0.jpg");
            Graphics g = Graphics.FromImage(bm);

            ab.GetBitmapFromDC = true;
            ab.stru = g.GetHdc();
            ab.paras = new MFVideoAlphaBitmapParams();
            ab.paras.dwFlags = MFVideoAlphaBitmapFlags.Alpha | MFVideoAlphaBitmapFlags.DestRect;

            ab.paras.fAlpha =  0.5f;

            ab.paras.nrcDest = new MFVideoNormalizedRect(0.5f, 0.5f, 1.0f, 1.0f);

            ab.paras.rcSrc = new MFRect(0, 0, bm.Width, bm.Height);

            int hr = m_vmb.SetAlphaBitmap(ab);
            MFError.ThrowExceptionForHR(hr);

            hr = m_vmb.GetAlphaBitmapParameters(abp);
            MFError.ThrowExceptionForHR(hr);

            // According the the docs, the graph must be running in order to call update
            hr = ((IMediaControl)m_pGraph).Run();
            MFError.ThrowExceptionForHR(hr);
            System.Threading.Thread.Sleep(1000);

            abp.fAlpha = .6f;
            abp.dwFlags |= MFVideoAlphaBitmapFlags.Alpha;

            hr = m_vmb.UpdateAlphaBitmapParameters(abp);
            MFError.ThrowExceptionForHR(hr);
            hr = m_vmb.GetAlphaBitmapParameters(abp2);
            MFError.ThrowExceptionForHR(hr);

            hr = m_vmb.ClearAlphaBitmap();
            MFError.ThrowExceptionForHR(hr);
        }
예제 #2
0
        private void menuItem14_Click(object sender, EventArgs e)
        {
            MFVideoAlphaBitmap alphaBmp = new MFVideoAlphaBitmap();

            using (Bitmap alphaBitmap = new Bitmap("epsonproj.png"))
            {

                //alphaBitmap is a 32bit semitransparent Bitmap
                Graphics g = Graphics.FromImage(alphaBitmap);

                // get pointer to needed objects
                IntPtr hdc = g.GetHdc();
                IntPtr memDC = CreateCompatibleDC(hdc);
                IntPtr hBitmap = alphaBitmap.GetHbitmap();
                IntPtr hOld = SelectObject(memDC, hBitmap);

                alphaBmp.GetBitmapFromDC = true;
                alphaBmp.stru = memDC;
                alphaBmp.paras = new MFVideoAlphaBitmapParams();
                alphaBmp.paras.dwFlags = MFVideoAlphaBitmapFlags.Alpha | MFVideoAlphaBitmapFlags.DestRect;

                // calculate destination rectangle
                MFVideoNormalizedRect mfNRect = new MFVideoNormalizedRect();
                //NormalizedRect nRect = GetDestRectangle(width, height, subtitleLines);

                mfNRect.top = 0.5f;// nRect.top;
                mfNRect.left = 0.5f;// nRect.left;
                mfNRect.right = 1.0f;//nRect.right;
                mfNRect.bottom = 1.0f;// nRect.bottom;

                // used when viewing half side by side anaglyph video that is stretched to full width
                //if (FrameMode == Mars.FrameMode.HalfSideBySide)
                //{
                //    mfNRect.left /= 2;
                //    mfNRect.right /= 2;
                //}

                alphaBmp.paras.nrcDest = mfNRect;

                // calculate source rectangle (full subtitle bitmap)
                MFRect rcSrc = new MFRect();
                rcSrc.bottom = alphaBitmap.Height;
                rcSrc.right = alphaBitmap.Width;
                rcSrc.top = 0;
                rcSrc.left = 0;

                alphaBmp.paras.rcSrc = rcSrc;

                // apply 1-bit transparency 
                //System.Drawing.Color colorKey = System.Drawing.Color.White;
                //alphaBmp.paras.clrSrcKey = ColorTranslator.ToWin32(colorKey);

                // 90% visible
                alphaBmp.paras.fAlpha = 0.5F;

                // set the bitmap to the evr mixer
                mixBmp.SetAlphaBitmap(alphaBmp);

                // cleanup
                SelectObject(memDC, hOld);
                DeleteDC(memDC);
                g.ReleaseHdc();
            }
        }