Exemplo n.º 1
0
        /// <summary>
        /// Create the grid pattern (squares) brush
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        BitmapBrush CreateGridPatternBrush(RenderTarget target)
        {
            // Create a compatible render target.
            BitmapRenderTarget compatibleRenderTarget =
                target.CreateCompatibleRenderTarget(CompatibleRenderTargetOptions.None, new SizeF(10.0f, 10.0f));

            //// Draw a pattern.
            SolidColorBrush spGridBrush = compatibleRenderTarget.CreateSolidColorBrush(new ColorF(0.93f, 0.94f, 0.96f, 1.0f));

            compatibleRenderTarget.BeginDraw();
            compatibleRenderTarget.FillRectangle(new RectF(0.0f, 0.0f, 10.0f, 1.0f), spGridBrush);
            compatibleRenderTarget.FillRectangle(new RectF(0.0f, 0.1f, 1.0f, 10.0f), spGridBrush);
            compatibleRenderTarget.EndDraw();

            //// Retrieve the bitmap from the render target.
            D2DBitmap spGridBitmap;

            spGridBitmap = compatibleRenderTarget.Bitmap;

            //// Choose the tiling mode for the bitmap brush.
            BitmapBrushProperties brushProperties = new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.Linear);

            //// Create the bitmap brush.
            return(renderTarget.CreateBitmapBrush(spGridBitmap, brushProperties));
        }