Esempio n. 1
0
        /// <summary>
        /// Clip the regions specified by the Geometry out of the frame buffer.
        /// </summary>
        public void ApplyClip(Geometry clip)
        {
            if (clip == null)
            {
                return;
            }
            Color[,] clipColors = TextureGenerator.RenderBrushToColorArray(GetClipBrush(clip), width, height);

            // Clipping is anti-aliased.  Need tolerance around clip edges.
            Color[,] tolColors = TextureGenerator.RenderBrushToColorArray(GetClipTolerance(clip), width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    double opacity = ColorOperations.ByteToDouble(clipColors[x, y].A);
                    frameBuffer[x, y] = ColorOperations.PreMultipliedOpacityScale(frameBuffer[x, y], opacity);

                    Color tolerance = new Color();
                    tolerance.A           = tolerance.R = tolerance.G = tolerance.B = tolColors[x, y].A;
                    toleranceBuffer[x, y] = ColorOperations.Add(toleranceBuffer[x, y], tolerance);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Render a brush to a buffer of given size at the current DPI setting
 /// </summary>
 public static Color[,] RenderBrushToColorArray(Brush b, int width, int height)
 {
     return(ColorOperations.ToColorArray(TextureGenerator.RenderBrushToImageData(b, width, height, Const.DpiX, Const.DpiY)));
 }