/// <summary> /// 初始化笔刷。 /// </summary> private void InitBrushes() { this.brush = new BitmapBrush(this.RenderTarget, null); this.shadowBrush = new BitmapBrush(this.RenderTarget, null); this.selectedBrush = new SolidColorBrush(this.RenderTarget, selectedColor); this.blackBrush = new SolidColorBrush(this.DeviceContext, Color.Black); }
public CustomTextRenderer(Direct2DFactory factory, WindowRenderTarget renderTarget, SolidColorBrush outlineBrush, BitmapBrush fillBrush) { _factory = factory; _renderTarget = renderTarget; _outlineBrush = outlineBrush; _fillBrush = fillBrush; }
public void UpdateSurfaceLedGroup() { if (_surfaceLedGroup == null) { // Apply the application wide brush and decorator BitmapBrush = new BitmapBrush(new Scale(_renderScaleSetting.Value), _sampleSizeSetting); _surfaceLedGroup = new ListLedGroup(Surface.Leds) { Brush = BitmapBrush }; return; } lock (_surfaceLedGroup) { // Clean up the old background _surfaceLedGroup.Detach(); // Apply the application wide brush and decorator BitmapBrush.Scale = new Scale(_renderScaleSetting.Value); _surfaceLedGroup = new ListLedGroup(Surface.Leds) { Brush = BitmapBrush }; } lock (BitmapBrush) { } }
public ImageBrushImpl( ITileBrush brush, SharpDX.Direct2D1.RenderTarget target, BitmapImpl bitmap, Size targetSize) { var dpi = new Vector(target.DotsPerInch.Width, target.DotsPerInch.Height); var calc = new TileBrushCalculator(brush, bitmap.PixelSize.ToSizeWithDpi(dpi), targetSize); if (!calc.NeedsIntermediate) { _bitmap = bitmap.GetDirect2DBitmap(target); PlatformBrush = new BitmapBrush( target, _bitmap.Value, GetBitmapBrushProperties(brush), GetBrushProperties(brush, calc.DestinationRect)); } else { using (var intermediate = RenderIntermediate(target, bitmap, calc)) { PlatformBrush = new BitmapBrush( target, intermediate.Bitmap, GetBitmapBrushProperties(brush), GetBrushProperties(brush, calc.DestinationRect)); } } _bitmapInterpolationMode = brush.BitmapInterpolationMode; }
public SpriteData(BitmapBrush bitmapBrush, int x, int y) { base.x = x; base.y = y; this.bitmapBrush = bitmapBrush; }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1)); this._yellowGreenBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(0x9ACD32, 1)); GradientStop[] stops = new GradientStop[] { new GradientStop(0, Color.FromKnown(Colors.Yellow, 1)), new GradientStop(1, Color.FromKnown(Colors.ForestGreen, 1)) }; using (GradientStopCollection collection = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp)) { this._linearGradientBrush = renderTarget.CreateLinearGradientBrush( new LinearGradientBrushProperties(new PointF(0, 0), new PointF(150, 150)), BrushProperties.Default, collection); this._radialGradientBrush = renderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties(new PointF(75, 75), new PointF(0, 0), 75, 75), BrushProperties.Default, collection); } using (Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "fern.jpg")) { this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.Linear), BrushProperties.Default); } this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromRGB(0.93f, 0.94f, 0.96f)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); // Create an array of gradient stops to put in the gradient stop // collection that will be used in the gradient brush. GradientStop[] stops = new GradientStop[] { new GradientStop(0, Color.FromKnown(Colors.Gold, 1)), new GradientStop(0.85f, Color.FromKnown(Colors.Orange, 1)), new GradientStop(1, Color.FromKnown(Colors.OrangeRed, 1)) }; using (GradientStopCollection gradiendStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp)) { // The center of the gradient is in the center of the box. // The gradient origin offset was set to zero(0, 0) or center in this case. this._radialGradientBrush = renderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties( new PointF(330, 330), new PointF(140, 140), 140, 140), BrushProperties.Default, gradiendStops); } this._sceneBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1)); this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromRGB(0.93f, 0.94f, 0.96f)); }
/// <summary> /// Initializes a new instance of the <see cref="TileBrushImpl"/> class. /// </summary> /// <param name="brush"></param> /// <param name="target"></param> /// <param name="targetSize"></param> public TileBrushImpl( TileBrush brush, SharpDX.Direct2D1.RenderTarget target, Size targetSize) { var helper = new TileBrushImplHelper(brush, targetSize); if (!helper.IsValid) { return; } using (var intermediate = new BitmapRenderTarget(target, CompatibleRenderTargetOptions.None, helper.IntermediateSize.ToSharpDX())) { using (var ctx = new RenderTarget(intermediate).CreateDrawingContext()) { intermediate.Clear(null); helper.DrawIntermediate(ctx); } PlatformBrush = new BitmapBrush( target, intermediate.Bitmap, GetBitmapBrushProperties(brush), GetBrushProperties(brush, helper.DestinationRect)); } }
public void modImage(string tag, BitmapBrush bitmapBrush) { if (_LSprite.ContainsKey(tag)) { _LSprite[tag].bitmapBrush = bitmapBrush; } }
private void CreateD2DRenderTargets() { // Create a D2D render target which can draw into our offscreen D3D surface textureRenderTarget = d2DFactory.CreateGraphicsSurfaceRenderTarget( textureSurface, renderTargetProperties ); // Create a linear gradient brush for the 2D geometry GradientStopCollection gradientStops = textureRenderTarget.CreateGradientStopCollection(stopsGeometry, Gamma.StandardRgb, ExtendMode.Mirror); linearGradientBrush = textureRenderTarget.CreateLinearGradientBrush( new LinearGradientBrushProperties( new Point2F(100, 0), new Point2F(100, 200)), gradientStops ); // create a black brush blackBrush = textureRenderTarget.CreateSolidColorBrush(new ColorF(GetColorValues(System.Windows.Media.Colors.Black))); using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream("Microsoft.WindowsAPICodePack.DirectX.Samples.tulip.jpg")) { d2dBitmap = BitmapUtilities.LoadBitmapFromStream( textureRenderTarget, imagingFactory, stream); } gridPatternBitmapBrush = CreateGridPatternBrush(textureRenderTarget); gridPatternBitmapBrush.Opacity = 0.5f; CreateBackBufferD2DRenderTarget(); }
public ImageBrushImpl( ITileBrush brush, SharpDX.Direct2D1.RenderTarget target, BitmapImpl bitmap, Size targetSize) { var calc = new TileBrushCalculator(brush, new Size(bitmap.PixelWidth, bitmap.PixelHeight), targetSize); if (!calc.NeedsIntermediate) { PlatformBrush = new BitmapBrush( target, bitmap.GetDirect2DBitmap(target), GetBitmapBrushProperties(brush), GetBrushProperties(brush, calc.DestinationRect)); } else { using (var intermediate = RenderIntermediate(target, bitmap, calc)) { PlatformBrush = new BitmapBrush( target, intermediate.Bitmap, GetBitmapBrushProperties(brush), GetBrushProperties(brush, calc.DestinationRect)); } } }
public D2DSpriteBitmapBrush(D2DSpriteBatch batch, D2DSpriteBitmap bitmap, BitmapBrushProperties bbp) { this._bitmap = bitmap; this._batch = batch; this._bitmapBrushProperties = bbp; this.Brush = new BitmapBrush(batch.DWRenderTarget, this._bitmap, bbp); this._batch.BatchDisposing += _batch_BatchDisposing; }
public void LoadGraphics(RenderTarget target) { var sprite = Properties.Resources.Ground.CreateDirectX2D1Bitmap(target); groundBrush = new BitmapBrush(target, sprite, new BitmapBrushProperties { ExtendModeX = ExtendMode.Wrap, ExtendModeY = ExtendMode.Wrap }); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._bitmap = renderTarget.CreateBitmap(this.GetType(), "fern.jpg"); this._brush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Orange, 1)); this._brush.Opacity = 0.75f; this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f)); }
/// <summary> /// 清除渲染使用的资源。 /// </summary> public override void ClearResources() { base.ClearResources(); if (this.brush != null) { this.brush.Dispose(); this.brush = null; } }
public ProcessBar(DeviceContext DC) : base(DC) { using (WICBitmap sc = Direct2DHelper.LoadBitmap("assets\\process.bmp")) using (D2DBitmap sc_cv = D2DBitmap.FromWicBitmap(HostDC, sc)) { br = new BitmapBrush(HostDC, sc_cv); } br.ExtendModeX = ExtendMode.Mirror; }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._outlineBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.DarkSlateBlue, 1), 1); this._shapeFillBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.CornflowerBlue, 1), 0.5f); this._textFillBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1), 1); this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f)); }
public VisualBrushImpl( VisualBrush brush, RenderTarget target, Size targetSize) { var visual = brush.Visual; var layoutable = visual as ILayoutable; if (layoutable?.IsArrangeValid == false) { layoutable.Measure(Size.Infinity); layoutable.Arrange(new Rect(layoutable.DesiredSize)); } 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 = (brush.TileMode & TileMode.FlipX) != 0 ? ExtendMode.Mirror : ExtendMode.Wrap; result.ExtendModeY = (brush.TileMode & TileMode.FlipY) != 0 ? ExtendMode.Mirror : ExtendMode.Wrap; if (brush.TileMode != TileMode.None) { result.Transform = SharpDX.Matrix3x2.Translation( (float)destinationRect.X, (float)destinationRect.Y); } PlatformBrush = result; } }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1)); using (Bitmap bitmap = renderTarget.CreateBitmap(this.GetType(), "flowers.jpg")) { this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.NearestNeighbor), BrushProperties.Default); } _customRenderer = new CustomTextRenderer(this.Direct2DFactory, renderTarget, this._blackBrush, this._bitmapBrush); }
public void modBackgroundImage(string tag, BitmapBrush bitmapBrush) { if (_LBackgroundSprite.ContainsKey(tag)) { _LBackgroundSprite[tag].bitmapBrush = bitmapBrush; } else { _LBackgroundSprite.TryAdd(tag, new SpriteData(bitmapBrush, 0, 0)); } }
//============================================================ // <T>重新加载。</T> //============================================================ public void Refresh() { // 释放对象 if (null != _native) { _native.Dispose(); } // 创建对象 _bitmapProperties.VerticalExtendMode = ExtendMode.Wrap; _bitmapProperties.HorizontalExtendMode = ExtendMode.Wrap; _native = new BitmapBrush(_device.Target, _bitmap.Native, _bitmapProperties); }
/// <summary> /// 准备渲染拼图碎片。 /// </summary> /// <param name="imageData">拼图使用的图片数据。</param> /// <param name="pieces">所有拼图碎片的集合。</param> /// <param name="rotatable">拼图碎片是否可以旋转。</param> /// <param name="ct">取消任务的通知。</param> public override void PrepareRender(byte[] imageData, JigsawPieceCollection pieces, bool rotatable, CancellationToken ct) { base.PrepareRender(imageData, pieces, rotatable, ct); if (this.brush == null) { this.brush = new BitmapBrush(this.RenderTarget, this.Image); } else { this.brush.Bitmap = this.Image; } }
private void UpdateBitmapBrush() { _bitmapBrush?.Dispose(); var extendMode = _extendMode >= (ExtendMode)3 ? ExtendMode.Clamp : _extendMode; _bitmapBrush = new BitmapBrush1(Renderer.Context2D, _bitmap, new BitmapBrushProperties1 { ExtendModeX = (SharpDX.Direct2D1.ExtendMode)extendMode, ExtendModeY = (SharpDX.Direct2D1.ExtendMode)extendMode, InterpolationMode = (InterpolationMode)_scalingMode }); }
/// <summary> /// 准备渲染拼图碎片。 /// </summary> /// <param name="imageData">拼图使用的图片数据。</param> /// <param name="pieces">所有拼图碎片的集合。</param> /// <param name="rotatable">拼图碎片是否可以旋转。</param> /// <param name="ct">取消任务的通知。</param> public override void PrepareRender(byte[] imageData, JigsawPieceCollection pieces, bool rotatable, CancellationToken ct) { base.PrepareRender(imageData, pieces, rotatable, ct); ct.ThrowIfCancellationRequested(); imageSize = new Size2((int)this.Image.Size.Width, (int)this.Image.Size.Height); using (Brush imageBrush = new BitmapBrush(this.DeviceContext, this.Image)) { using (Bitmap1 source = DeviceManager.CreateBitmap(imageSize)) { ct.ThrowIfCancellationRequested(); // 设置特效的输入。 bevelBaseEffect.SetInput(0, source, true); bevelEffect.SetInput(0, source, true); // 分别按黑色与白色创建拼图碎片特效。 List <Geometry> blacks = new List <Geometry>(); List <Geometry> whites = new List <Geometry>(); foreach (JigsawPiece piece in pieces) { Geometry[] geoms = piece.OriginalPath.GetSourceGeometry(); // 划分黑色与白色,他们分别是不相邻的。 bool[] colors = piece.GetColors(); for (int i = 0; i < colors.Length; i++) { if (colors[i]) { blacks.Add(geoms[i]); } else { whites.Add(geoms[i]); } } } ct.ThrowIfCancellationRequested(); pointSpecularEffect.LightPosition = new Vector3(0, 0, 0); this.images[0] = this.CreateImage(imageBrush, source, blacks, whites, ct); if (rotatable) { // 生成不同旋转角度的图像,使用不同的光照情况。 pointSpecularEffect.LightPosition = new Vector3(0, imageSize.Height, 0); this.images[1] = this.CreateImage(imageBrush, source, blacks, whites, ct); pointSpecularEffect.LightPosition = new Vector3(imageSize.Width, imageSize.Height, 0); this.images[2] = this.CreateImage(imageBrush, source, blacks, whites, ct); pointSpecularEffect.LightPosition = new Vector3(imageSize.Width, 0, 0); this.images[3] = this.CreateImage(imageBrush, source, blacks, whites, ct); } } } }
/// <summary> /// Draws a bitmap image. /// </summary> /// <param name="source">The bitmap image.</param> /// <param name="opacityMask">The opacity mask to draw with.</param> /// <param name="opacityMaskRect">The destination rect for the opacity mask.</param> /// <param name="destRect">The rect in the output to draw to.</param> public void DrawImage(IBitmapImpl source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect) { using (var d2dSource = ((BitmapImpl)source).GetDirect2DBitmap(_renderTarget)) using (var sourceBrush = new BitmapBrush(_renderTarget, d2dSource)) using (var d2dOpacityMask = CreateBrush(opacityMask, opacityMaskRect.Size)) using (var geometry = new SharpDX.Direct2D1.RectangleGeometry(_renderTarget.Factory, destRect.ToDirect2D())) { d2dOpacityMask.PlatformBrush.Transform = Matrix.CreateTranslation(opacityMaskRect.Position).ToDirect2D(); _renderTarget.FillGeometry( geometry, sourceBrush, d2dOpacityMask.PlatformBrush); } }
/// <summary> /// Draw the rectangle on layer with layerIndex /// </summary> /// <param name="layerIndex"></param> /// <param name="rectangle"></param> /// <param name="bitmap"></param> /// <param name="borderColor"></param> /// <param name="opacity"></param> public void Draw(int layerIndex, System.Drawing.RectangleF rectangle, System.Drawing.Bitmap bitmap, System.Drawing.Color?borderColor, float opacity = 1) { if (bitmap != prevBitmap) { prevBitmap = bitmap; bitmapBrush = new BitmapBrush(device.renderTarget, Convertor.ConvertDrawingBmpToDirectxBmp(device.renderTarget, prevBitmap)); bitmapBrush.InterpolationMode = BitmapInterpolationMode.Linear; bitmapBrush.Opacity = opacity; bitmapBrush.ExtendModeX = ExtendMode.Wrap; bitmapBrush.ExtendModeY = ExtendMode.Wrap; } device.layers[layerIndex].FillRectangle(new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height), bitmapBrush); if (borderColor != null) { device.layers[layerIndex].DrawRectangle(new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height), new SharpDX.Direct2D1.SolidColorBrush(device.renderTarget, xPFT.DrawingBase.Convertor.ColorConvertor((System.Drawing.Color)borderColor, opacity)), lineWidth); } }
/// <summary> /// This method creates the render target and all associated D2D and DWrite resources /// </summary> void CreateDeviceResources() { // Only calls if resources have not been initialize before if (renderTarget == null) { // The text format textFormat = dwriteFactory.CreateTextFormat("Bodoni MT", 24, DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, DWrite.FontStretch.Normal); // Create the render target SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight); RenderTargetProperties props = new RenderTargetProperties(); HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None); renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps); // A black brush to be used for drawing text ColorF cf = new ColorF(0, 0, 0, 1); blackBrush = renderTarget.CreateSolidColorBrush(cf); // Create a linear gradient. GradientStop[] stops = { new GradientStop(1, new ColorF(1f, 0f, 0f, 0.25f)), new GradientStop(0, new ColorF(0f, 0f, 1f, 1f)) }; GradientStopCollection pGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap); LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties(new Point2F(50, 25), new Point2F(25, 50)); linearGradientBrush = renderTarget.CreateLinearGradientBrush(gradBrushProps, pGradientStops); gridPatternBitmapBrush = CreateGridPatternBrush(renderTarget); solidBrush1 = renderTarget.CreateSolidColorBrush(new ColorF(0.3F, 0.5F, 0.65F, 0.25F)); solidBrush2 = renderTarget.CreateSolidColorBrush(new ColorF(0.0F, 0.0F, 0.65F, 0.5F)); solidBrush3 = renderTarget.CreateSolidColorBrush(new ColorF(0.9F, 0.5F, 0.3F, 0.75F)); // Create a linear gradient. stops[0] = new GradientStop(1, new ColorF(0f, 0f, 0f, 0.25f)); stops[1] = new GradientStop(0, new ColorF(1f, 1f, 0.2f, 1f)); GradientStopCollection radiantGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap); RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties(new Point2F(25, 25), new Point2F(0, 0), 10, 10); radialGradientBrush = renderTarget.CreateRadialGradientBrush(radialBrushProps, radiantGradientStops); } }
/// <summary> /// Draws a bitmap image. /// </summary> /// <param name="source">The bitmap image.</param> /// <param name="opacityMask">The opacity mask to draw with.</param> /// <param name="opacityMaskRect">The destination rect for the opacity mask.</param> /// <param name="destRect">The rect in the output to draw to.</param> public void DrawImage(IRef <IBitmapImpl> source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect) { using (var d2dSource = ((BitmapImpl)source.Item).GetDirect2DBitmap(_deviceContext)) using (var sourceBrush = new BitmapBrush(_deviceContext, d2dSource.Value)) using (var d2dOpacityMask = CreateBrush(opacityMask, opacityMaskRect.Size)) using (var geometry = new SharpDX.Direct2D1.RectangleGeometry(_deviceContext.Factory, destRect.ToDirect2D())) { if (d2dOpacityMask.PlatformBrush != null) { d2dOpacityMask.PlatformBrush.Transform = Matrix.CreateTranslation(opacityMaskRect.Position).ToDirect2D(); } _deviceContext.FillGeometry( geometry, sourceBrush, d2dOpacityMask.PlatformBrush); } }
private void addBitmapBrushBotton_Click(object sender, EventArgs e) { ExtendMode ex = extendedModeXComboBox.SelectedIndex > 0 ? (ExtendMode)extendedModeXComboBox.SelectedIndex : ExtendMode.Wrap; ExtendMode ey = extendedModeYComboBox.SelectedIndex > 0 ? (ExtendMode)extendedModeYComboBox.SelectedIndex : ExtendMode.Wrap; D2DBitmap brushBitmap = BitmapUtilities.LoadBitmapFromFile(renderTarget, parent.wicFactory, imageFilename); BitmapBrush brush = renderTarget.CreateBitmapBrush( brushBitmap, new BitmapBrushProperties( ex, ey, BitmapInterpolationMode.NearestNeighbor), new BrushProperties( opacity, Matrix3x2F.Identity)); parent.brushes.Add(brush); parent.currentBrushIndex = parent.brushes.Count - 1; FillBrushesListBox(); }
internal override void Create() { if (NativeBrush != null) { NativeBrush.Dispose(); } m_bitmap.Create(); var props = new BitmapBrushProperties(); props.InterpolationMode = BitmapInterpolationMode.Linear; NativeBrush = new BitmapBrush(Owner.D2dRenderTarget, m_bitmap.NativeBitmap, props); ExtendModeX = m_extendModeX; ExtendModeY = m_extendModeY; InterpolationMode = D2dBitmapInterpolationMode.Linear; Location = m_location; Bitmap = m_bitmap; }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); // Create an array of gradient stops to put in the gradient stop // collection that will be used in the gradient brush. GradientStop[] stops = new GradientStop[] { new GradientStop(0, Color.FromARGB(Colors.Gold, 1)), new GradientStop(0.85f, Color.FromARGB(Colors.Orange, 1)), new GradientStop(1, Color.FromARGB(Colors.OrangeRed, 1)) }; using (GradientStopCollection gradiendStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp)) { // The center of the gradient is in the center of the box. // The gradient origin offset was set to zero(0, 0) or center in this case. this._radialGradientBrush = renderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties( new PointF(330, 330), new PointF(140, 140), 140, 140), BrushProperties.Default, gradiendStops); } this._sceneBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1)); this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1)); this._yellowGreenBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(0x9ACD32, 1)); GradientStop[] stops = new GradientStop[] { new GradientStop(0, Color.FromARGB(Colors.Yellow, 1)), new GradientStop(1, Color.FromARGB(Colors.ForestGreen, 1)) }; using (GradientStopCollection collection = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp)) { this._linearGradientBrush = renderTarget.CreateLinearGradientBrush( new LinearGradientBrushProperties(new PointF(0, 0), new PointF(150, 150)), BrushProperties.Default, collection); this._radialGradientBrush = renderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties(new PointF(75, 75), new PointF(0, 0), 75, 75), BrushProperties.Default, collection); } using (Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "fern.jpg")) { this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.Linear), BrushProperties.Default); } this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1)); using (Bitmap bitmap = renderTarget.CreateBitmap(this.GetType(), "flowers.jpg")) { this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.NearestNeighbor), BrushProperties.Default); } _customRenderer = new CustomTextRenderer(this.Direct2DFactory, renderTarget, this._blackBrush, this._bitmapBrush); }