本文整理汇总了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));
}
}
示例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;
//}
}