Ejemplo n.º 1
0
        public bool SaveBitmap(Bitmap bitmap, bool show, bool transparent, float alphaValue)
        {
            if (!_isVmr9Initialized)
            {
                return(false);
            }
            if (_vmr9Filter == null)
            {
                return(false);
            }

            if (MixerBitmapInterface == null)
            {
                return(false);
            }

            if (GUIGraphicsContext.Vmr9Active == false)
            {
                Log.Info("SaveVMR9Bitmap() failed - no VMR9");
                return(false);
            }
            int hr = 0;

            // transparent image?
            using (MemoryStream mStr = new MemoryStream())
            {
                if (bitmap != null)
                {
                    if (transparent == true)
                    {
                        bitmap.MakeTransparent(Color.Black);
                    }
                    bitmap.Save(mStr, ImageFormat.Bmp);
                    mStr.Position = 0;
                }

                VMR9AlphaBitmap bmp = new VMR9AlphaBitmap();

                if (show == true)
                {
                    // get AR for the bitmap
                    Rectangle src, dest;
                    g_vmr9.GetVideoWindows(out src, out dest);

                    int width  = g_vmr9.VideoWidth;
                    int height = g_vmr9.VideoHeight;

                    float xx = (float)src.X / width;
                    float yy = (float)src.Y / height;
                    float fx = (float)(src.X + src.Width) / width;
                    float fy = (float)(src.Y + src.Height) / height;
                    //

                    using (
                        Surface surface = GUIGraphicsContext.DX9Device.CreateOffscreenPlainSurface(GUIGraphicsContext.Width,
                                                                                                   GUIGraphicsContext.Height,
                                                                                                   Format.X8R8G8B8,
                                                                                                   Pool.SystemMemory))
                    {
                        SurfaceLoader.FromStream(surface, mStr, Filter.None, 0);
                        bmp.dwFlags   = (VMR9AlphaBitmapFlags)(4 | 8);
                        bmp.clrSrcKey = 0;
                        unsafe
                        {
                            bmp.pDDS = (IntPtr)surface.UnmanagedComPointer;
                        }
                        bmp.rDest        = new NormalizedRect();
                        bmp.rDest.top    = yy;
                        bmp.rDest.left   = xx;
                        bmp.rDest.bottom = fy;
                        bmp.rDest.right  = fx;
                        bmp.fAlpha       = alphaValue;
                        //Log.Info("SaveVMR9Bitmap() called");
                        hr = g_vmr9.MixerBitmapInterface.SetAlphaBitmap(ref bmp);
                        if (hr != 0)
                        {
                            //Log.Info("SaveVMR9Bitmap() failed: error {0:X} on SetAlphaBitmap()",hr);
                            return(false);
                        }
                    }
                }
                else
                {
                    bmp.dwFlags      = (VMR9AlphaBitmapFlags)1;
                    bmp.clrSrcKey    = 0;
                    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;
                    hr = g_vmr9.MixerBitmapInterface.UpdateAlphaBitmapParameters(ref bmp);
                    if (hr != 0)
                    {
                        return(false);
                    }
                }
            }
            // dispose
            return(true);
        }