FillOpacityMask() public method

Applies the opacity mask described by the specified bitmap to a brush and uses that brush to paint a region of the render target.
For this method to work properly, the render target must be using the F:SharpDX.Direct2D1.AntialiasMode.Aliased antialiasing mode. You can set the antialiasing mode by calling the M:SharpDX.Direct2D1.RenderTarget.SetAntialiasMode(SharpDX.Direct2D1.AntialiasMode) method. This method doesn't return an error code if it fails. To determine whether a drawing operation (such as {{FillOpacityMask}}) failed, check the result returned by the M:SharpDX.Direct2D1.RenderTarget.EndDraw(System.Int64@,System.Int64@) or M:SharpDX.Direct2D1.RenderTarget.Flush(System.Int64@,System.Int64@) methods.
public FillOpacityMask ( Bitmap opacityMask, Brush brush, OpacityMaskContent content ) : void
opacityMask Bitmap The opacity mask to apply to the brush. The alpha value of each pixel in the region specified by sourceRectangle is multiplied with the alpha value of the brush after the brush has been mapped to the area defined by destinationRectangle.
brush Brush The brush used to paint the region of the render target specified by destinationRectangle.
content OpacityMaskContent The type of content the opacity mask contains. The value is used to determine the color space in which the opacity mask is blended.
return void
Exemplo n.º 1
0
        public void EndDraw()
        {
            if (_sbObj.IsFinished || _timing.Offset < _sbObj.MinTime || _sbObj.F.RealTime <= 0)
            {
                if (_flag)
                {
                    _sbObj.ResetRealTime();
                    _flag = false;
                }
                return;
            }

            _flag = true;
            if (_sbObj is AnimatedObject ani && _timing.Offset >= ani.MinTime && _timing.Offset <= ani.MaxTime)
            {
                int imgIndex;
                if (ani.Loop)
                {
                    imgIndex = (int)((_timing.Offset - ani.MinTime) / ani.Delay % ani.Times);
                }
                else
                {
                    imgIndex = (int)((_timing.Offset - ani.MinTime) / ani.Delay);
                    if (imgIndex >= ani.Times)
                    {
                        imgIndex = ani.Times - 1;
                    }
                }

                if (imgIndex != ani.PrevIndex)
                {
                    ani.PrevIndex = imgIndex;
                    ani.Texture   = ani.TextureList[imgIndex];
                }
            }


            var translateMtx    = Matrix3x2.Translation(-_sbObj.X.RealTime, -_sbObj.Y.RealTime);
            var scaleMtx        = Matrix3x2.Scaling((_sbObj.UseH ? -1 : 1) * _sbObj.Vx.RealTime, (_sbObj.UseV ? -1 : 1) * _sbObj.Vy.RealTime);
            var rotateMtx       = Matrix3x2.Rotation(_sbObj.Rad.RealTime);
            var negTranslateMtx = Matrix3x2.Translation(_sbObj.X.RealTime, _sbObj.Y.RealTime);

            _target.Transform = translateMtx * scaleMtx * rotateMtx * negTranslateMtx;

            float rectL = _sbObj.Rect.RealTime.Left - _sbObj.OriginOffsetX - (_sbObj.UseH ? 2 * (_sbObj.Width / 2 - _sbObj.OriginOffsetX) : 0);
            float rectT = _sbObj.Rect.RealTime.Top - _sbObj.OriginOffsetY - (_sbObj.UseV ? 2 * (_sbObj.Height / 2 - _sbObj.OriginOffsetY) : 0);
            float rectW = _sbObj.Rect.RealTime.Right - _sbObj.Rect.RealTime.Left;
            float rectH = _sbObj.Rect.RealTime.Bottom - _sbObj.Rect.RealTime.Top;

            var realRect = new RectangleF(rectL, rectT, rectW, rectH);

            if (_sbObj.Texture != null)
            {
                if (_sbObj.R.RealTime != 255 || _sbObj.G.RealTime != 255 || _sbObj.B.RealTime != 255)
                {
                    //JUST FAKE THING
                    var sb = new D2D.SolidColorBrush(_target,
                                                     new Mathe.RawColor4(_sbObj.R.RealTime / 255f, _sbObj.G.RealTime / 255f,
                                                                         _sbObj.B.RealTime / 255f, _sbObj.F.RealTime));
                    _target.FillOpacityMask(_sbObj.Texture, sb, D2D.OpacityMaskContent.Graphics, realRect, null);
                    sb.Dispose();
                    sb = null;
                }
                else
                {
                    _target.DrawBitmap(_sbObj.Texture, realRect, _sbObj.F.RealTime, D2D.BitmapInterpolationMode.Linear);
                }
            }

#if DEBUG
            //_target.DrawRectangle(realRect, _redBrush, 1);
#endif
            _target.Transform = new Matrix3x2(1, 0, 0, 1, 0, 0);
        }