當前位置: 首頁>>代碼示例>>C#>>正文


C# RenderTarget.CreateDrawingContext方法代碼示例

本文整理匯總了C#中SharpDX.Direct2D1.RenderTarget.CreateDrawingContext方法的典型用法代碼示例。如果您正苦於以下問題:C# RenderTarget.CreateDrawingContext方法的具體用法?C# RenderTarget.CreateDrawingContext怎麽用?C# RenderTarget.CreateDrawingContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SharpDX.Direct2D1.RenderTarget的用法示例。


在下文中一共展示了RenderTarget.CreateDrawingContext方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: VisualBrushImpl

        public VisualBrushImpl(
            VisualBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size targetSize)
        {
            var visual = brush.Visual;

            if (visual == null)
            {
                return;
            }

            var layoutable = visual as ILayoutable;

            if (layoutable?.IsArrangeValid == false)
            {
                layoutable.Measure(Size.Infinity);
                layoutable.Arrange(new Rect(layoutable.DesiredSize));
            }

            var tileMode = brush.TileMode;
            var sourceRect = brush.SourceRect.ToPixels(layoutable.Bounds.Size);
            var destinationRect = brush.DestinationRect.ToPixels(targetSize);
            var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);
            var brtOpts = CompatibleRenderTargetOptions.None;

            // TODO: There are times where we don't need to draw an intermediate bitmap. Identify
            // them and directly use 'image' in those cases.
            using (var intermediate = new BitmapRenderTarget(target, brtOpts, intermediateSize))
            {
                Rect drawRect;
                var transform = CalculateIntermediateTransform(
                    tileMode,
                    sourceRect,
                    destinationRect,
                    scale,
                    translate,
                    out drawRect);
                var renderer = new RenderTarget(intermediate);

                using (var ctx = renderer.CreateDrawingContext())
                using (ctx.PushClip(drawRect))
                using (ctx.PushPostTransform(transform))
                {
                    intermediate.Clear(new Color4(0));
                    ctx.Render(visual);
                }

                this.PlatformBrush = new BitmapBrush(
                    target,
                    intermediate.Bitmap,
                    GetBitmapBrushProperties(brush),
                    GetBrushProperties(brush, destinationRect));
            }
        }
開發者ID:rdterner,項目名稱:Perspex,代碼行數:57,代碼來源:VisualBrushImpl.cs

示例2: VisualBrushImpl

        public VisualBrushImpl(
            VisualBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size targetSize)
        {
            var visual = brush.Visual;

            if (visual == null)
            {
                return;
            }

            var layoutable = visual as ILayoutable;

            if (layoutable?.IsArrangeValid == false)
            {
                layoutable.Measure(Size.Infinity);
                layoutable.Arrange(new Rect(layoutable.DesiredSize));
            }

            var tileMode = brush.TileMode;
            var sourceRect = brush.SourceRect.ToPixels(layoutable.Bounds.Size);
            var destinationRect = brush.DestinationRect.ToPixels(targetSize);
            var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);
            var brtOpts = CompatibleRenderTargetOptions.None;

            // TODO: There are times where we don't need to draw an intermediate bitmap. Identify
            // them and directly use 'image' in those cases.
            using (var intermediate = new BitmapRenderTarget(target, brtOpts, intermediateSize))
            {
                Rect drawRect;
                var transform = CalculateIntermediateTransform(
                    tileMode,
                    sourceRect,
                    destinationRect,
                    scale,
                    translate,
                    out drawRect);
                var renderer = new RenderTarget(intermediate);

                using (var ctx = renderer.CreateDrawingContext())
                using (ctx.PushClip(drawRect))
                using (ctx.PushPostTransform(transform))
                {
                    ctx.Render(visual);
                }
                this.PlatformBrush = new BitmapBrush(
                    target,
                    intermediate.Bitmap,
                    GetBitmapBrushProperties(brush),
                    GetBrushProperties(brush, destinationRect));
            }

            //var sourceRect = brush.SourceRect.ToPixels(layoutable.Bounds.Size);
            //var destinationRect = brush.DestinationRect.ToPixels(targetSize);
            //var bitmapSize = brush.TileMode == TileMode.None ? targetSize : destinationRect.Size;
            //var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            //var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            //var options = CompatibleRenderTargetOptions.None;

            //using (var brt = new BitmapRenderTarget(target, options, bitmapSize.ToSharpDX()))
            //{
            //    var renderer = new Renderer(brt);
            //    var transform = Matrix.CreateTranslation(-sourceRect.Position) *
            //                    Matrix.CreateScale(scale) *
            //                    Matrix.CreateTranslation(translate);

            //    Rect drawRect;

            //    if (brush.TileMode == TileMode.None)
            //    {
            //        drawRect = destinationRect;
            //        transform *= Matrix.CreateTranslation(destinationRect.Position);
            //    }
            //    else
            //    {
            //        drawRect = new Rect(0, 0, destinationRect.Width, destinationRect.Height);
            //    }

            //    renderer.Render(visual, null, transform, drawRect);

            //    var result = new BitmapBrush(brt, brt.Bitmap);
            //    result.ExtendModeX = GetExtendModeX(brush.TileMode);
            //    result.ExtendModeY = GetExtendModeY(brush.TileMode);

            //    if (brush.TileMode != TileMode.None)
            //    {
            //        result.Transform = SharpDX.Matrix3x2.Translation(
            //            (float)destinationRect.X,
            //            (float)destinationRect.Y);
            //    }

            //    PlatformBrush = result;
            //}
        }
開發者ID:hacklex,項目名稱:Perspex,代碼行數:97,代碼來源:VisualBrushImpl.cs


注:本文中的SharpDX.Direct2D1.RenderTarget.CreateDrawingContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。