• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Direct2D1.SolidColorBrush类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SharpDX.Direct2D1.SolidColorBrush的典型用法代码示例。如果您正苦于以下问题:C# SolidColorBrush类的具体用法?C# SolidColorBrush怎么用?C# SolidColorBrush使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SolidColorBrush类属于SharpDX.Direct2D1命名空间,在下文中一共展示了SolidColorBrush类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SharpDXDrawing

 public SharpDXDrawing(SharpDXDevice device)
     : base(device)
 {
     this.device = device;
     solidColorBrush = new SolidColorBrush(device.RenderTarget, Colors.Black);
     device.RenderTarget.Transform = Matrix3x2.Identity;
 }
开发者ID:lilinghui,项目名称:DeltaEngine,代码行数:7,代码来源:SharpDXDrawing.cs


示例2: OnLoad

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
 
            // Direct2D
            var renderTargetProperties = new RenderTargetProperties()
            {
                PixelFormat = new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Ignore)
            };
            var hwndRenderTargetProperties = new HwndRenderTargetProperties()
            {
                Hwnd = this.Handle,
                PixelSize = new Size2(bounds.Width, bounds.Height),
                PresentOptions = PresentOptions.Immediately,
            };
            renderTarget = new WindowRenderTarget(factory, renderTargetProperties, hwndRenderTargetProperties);

            var bitmapProperties = new BitmapProperties()
            {
                PixelFormat = new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Ignore)
            };
            bitmap = new SharpDX.Direct2D1.Bitmap(renderTarget, new Size2(bounds.Width, bounds.Height), bitmapProperties);

            textFormat = new TextFormat(directWriteFacrtory, "Arial", FontWeight.Normal, SharpDX.DirectWrite.FontStyle.Normal, 96.0f);
            textFormat.ParagraphAlignment = ParagraphAlignment.Center;
            textFormat.TextAlignment = TextAlignment.Center;

            solidColorBrush = new SolidColorBrush(renderTarget, Color4.White);
        }
开发者ID:dmak78,项目名称:RoomAliveToolkit,代码行数:29,代码来源:ProjectorForm.cs


示例3: InfoText

        public InfoText(SharpDX.Direct3D11.Device device, int width, int height)
        {
            _immediateContext = device.ImmediateContext;
            _rect.Size = new Size2F(width, height);
            _bitmapSize = width * height * 4;
            IsEnabled = true;

            using (var factoryWic = new SharpDX.WIC.ImagingFactory())
            {
                _wicBitmap = new SharpDX.WIC.Bitmap(factoryWic,
                    width, height, _pixelFormat, SharpDX.WIC.BitmapCreateCacheOption.CacheOnLoad);
            }

            var renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default,
                new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm,
                    SharpDX.Direct2D1.AlphaMode.Premultiplied), 0, 0, RenderTargetUsage.None,
                    SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT);

            using (var factory2D = new SharpDX.Direct2D1.Factory())
            {
                _wicRenderTarget = new WicRenderTarget(factory2D, _wicBitmap, renderTargetProperties);
                _wicRenderTarget.TextAntialiasMode = TextAntialiasMode.Default;
            }

            using (var factoryDWrite = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared))
            {
                _textFormat = new TextFormat(factoryDWrite, "Tahoma", 20);
            }

            Color4 color = new Color4(1, 1, 1, 1);
            _sceneColorBrush = new SolidColorBrush(_wicRenderTarget, color);
            _clearColor = color;
            _clearColor.Alpha = 0;

            _renderTexture = new Texture2D(device, new Texture2DDescription()
            {
                ArraySize = 1,
                BindFlags = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.Write,
                Format = Format.R8G8B8A8_UNorm,
                Height = height,
                Width = width,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Dynamic
            });

            OverlayBufferRes = new ShaderResourceView(device, _renderTexture, new ShaderResourceViewDescription()
            {
                Format = _renderTexture.Description.Format,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels = 1,
                    MostDetailedMip = 0
                }
            });
        }
开发者ID:sinkingsugar,项目名称:BulletSharpPInvoke,代码行数:59,代码来源:InfoText.cs


示例4: Initialize

 //public static Brush TEXT_BRUSH;
 public static void Initialize(RenderTarget g)
 {
     SCBRUSH_RED = new SolidColorBrush(g, Color.Red);
     SCBRUSH_BLACK = new SolidColorBrush(g, Color.Black);
     WRITE_FACTORY = new SharpDX.DirectWrite.Factory();
     TEXT_FORMAT = new TextFormat(WRITE_FACTORY, "Arial", 14);
     //TEXT_BRUSH = new SolidColorBrush(g, Color.Red);
 }
开发者ID:Harrum,项目名称:TestGamePlsIgnore,代码行数:9,代码来源:Resources.cs


示例5: SolidColorBrush

 public SolidColorBrush(D2D.RenderTarget target, Color color)
 {
     if (target != null)
     {
         d2dBrush = new D2D.SolidColorBrush(target, color.ToD2D());
     }
     else
         throw new ArgumentNullException();
 }
开发者ID:denismaster,项目名称:Seal,代码行数:9,代码来源:SolidColorBrush.cs


示例6: InitializeResources

 internal void InitializeResources(RenderTarget d2dRenderTarget)
 {
     if (!initialized)
     {
         Fill = new SolidColorBrush(d2dRenderTarget, Colors.Green);
         Stroke = new SolidColorBrush(d2dRenderTarget, Colors.Azure);
         initialized = true;
        texture = MainGame.LoadFromFile(d2dRenderTarget, @"C:\git\KinectLight\resources\Logo_EDGE_40.bmp");
     }
 }
开发者ID:aL3891,项目名称:KinectLight,代码行数:10,代码来源:ThingBase.cs


示例7: SharpDXDrawing

 public SharpDXDrawing(SharpDXDevice device, Window window)
     : base(device)
 {
     this.device = device;
     brush = new SolidColorBrush(device.RenderTarget, new Color4(lastColor.PackedRgba));
     device.RenderTarget.Transform = Matrix3x2.Identity;
     drawShader = new SharpDXDrawShader(device);
     Reset(window.ViewportPixelSize);
     window.ViewportSizeChanged += Reset;
     device.Context.OutputMerger.BlendState = device.GetAlphaBlendStateLazy();
 }
开发者ID:hillwhite,项目名称:DeltaEngine,代码行数:11,代码来源:SharpDXDrawing.cs


示例8: TextDX

 /* CONSTRUCTOR METHOD */
 /// <summary>
 /// Constructs a 2D block of text that can displayed in a 3D rendering window.
 /// </summary>
 /// <param name="window">A reference to a Direct3D-capable rendering window.</param>
 public TextDX(Window3D window)
     : base(window)
 {
     ColorBrush		= Tag(new SolidColorBrush(RenderTarget, Color4.Black));
     Font			= "Calibri";
     Size			= 16f;
     Style			= FontStyle.Normal;
     Text			= string.Empty;
     UpdateSettings	= true;
     Weight			= FontWeight.Normal;
 }
开发者ID:JoshGrooms,项目名称:Tesseract,代码行数:16,代码来源:TextDX.cs


示例9: Create3dObjects

        public void Create3dObjects()
        {
            //Create RenderWindow
            RenderWindowInstance = new ModelRenderWindow();
            FormInstance = RenderWindowInstance.CreateWindow(1080,1240,FormStartPosition.CenterScreen);

            //Create SwapChain
            SwapChainCreator = new ModelSwapChainDesc();
            SwapChainD = SwapChainCreator.CreateSwapChain(2, Usage.RenderTargetOutput, FormInstance.Handle, true, 0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm, 1,0,SwapChainFlags.AllowModeSwitch, SwapEffect.Discard);

            //Create Device
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, SwapChainD, out GraphicsDevice, out NewSwapChain);

            //Create Back buffer
            BackBuffer = Surface.FromSwapChain(NewSwapChain, 0);

            //Create Factory
            FactoryD2D FactoryInstance = new FactoryD2D();

            //Create RenderTarget
            RenderTargetInstance = new ModelRenderTarget();
            RenderTarget = RenderTargetInstance.CreateRenderTarget(SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT, new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Ignore), RenderTargetType.Default, RenderTargetUsage.None, BackBuffer, FactoryInstance);

            RenderLoop.Run(FormInstance, () =>
            {

                RenderTarget.BeginDraw();
                RenderTarget.Transform = Matrix3x2.Identity;
                RenderTarget.Clear(Color.White);

                using (var brush = new SolidColorBrush(RenderTarget, Color.Red))
                {
                    //for (int x = 0; x < RenderTarget.Size.Width; x += 10)
                    //    RenderTarget.DrawLine(new Vector2(x, 0), new Vector2(x, RenderTarget.Size.Height), brush, 0.5f);

                    //for (int y = 0; y < RenderTarget.Size.Height; y += 10)
                    //    RenderTarget.DrawLine(new Vector2(0, y), new Vector2(RenderTarget.Size.Width, y), brush, 0.5f);
                    RenderTarget.DrawLine(new Vector2(300, 10), new Vector2(300, 300), brush,1.5f);
                   // RenderTarget.FillRectangle(new RectangleF(RenderTarget.Size.Width / 2 - 50, RenderTarget.Size.Height / 2 - 50, 100, 100), brush);
                }

              //  RenderTarget.DrawRectangle(
                   // new RectangleF(RenderTarget.Size.Width / 2 - 100, RenderTarget.Size.Height / 2 - 100, 200, 200),
                   // new SolidColorBrush(RenderTarget, Color.CornflowerBlue));

                RenderTarget.EndDraw();

                NewSwapChain.Present(0, PresentFlags.None);
            });

            RenderTarget.Dispose();
            NewSwapChain.Dispose();
            GraphicsDevice.Dispose();
        }
开发者ID:thornhillad,项目名称:Test3dEngine,代码行数:54,代码来源:ThreeDeeObjects.cs


示例10: Panel

 /* CONSTRUCTOR & DESTRUCTOR METHODS */
 /// <summary>
 /// Constructs a generic 2D rectangular panel that will be displayed as a flat, image-like rendering in the 3D rendering window.
 /// </summary>
 /// <param name="window">A reference to a Direct3D-capable rendering window in which this entity will be displayed.</param>
 protected Panel(Window3D window)
     : base(window)
 {
     BackgroundBrush = Tag(new SolidColorBrush(RenderTarget, Color.SlateGray));
     BorderBrush = Tag(new SolidColorBrush(RenderTarget, Color.SlateGray));
     Rectangle = new RoundedRectangle()
     {
         RadiusX = 0f,
         RadiusY = 0f,
         Rect = new RectangleF(0, 0, 100, 100),
     };
 }
开发者ID:JoshGrooms,项目名称:Tesseract,代码行数:17,代码来源:Panel.cs


示例11: Main

        private static void Main()
        {
            var wicFactory = new ImagingFactory();
            var d2dFactory = new SharpDX.Direct2D1.Factory();

            string filename = "output.jpg";
            const int width = 512;
            const int height = 512;

            var rectangleGeometry = new RoundedRectangleGeometry(d2dFactory, new RoundedRectangle() { RadiusX = 32, RadiusY = 32, Rect = new RectangleF(128, 128, width - 128, height-128) });

            var wicBitmap = new Bitmap(wicFactory, width, height, SharpDX.WIC.PixelFormat.Format32bppBGR, BitmapCreateCacheOption.CacheOnLoad);

            var renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default, new PixelFormat(Format.Unknown, AlphaMode.Unknown), 0, 0, RenderTargetUsage.None, FeatureLevel.Level_DEFAULT);

            var d2dRenderTarget = new WicRenderTarget(d2dFactory, wicBitmap, renderTargetProperties);

            var solidColorBrush = new SolidColorBrush(d2dRenderTarget, Color.White);

            d2dRenderTarget.BeginDraw();
            d2dRenderTarget.Clear(Color.Black);
            d2dRenderTarget.FillGeometry(rectangleGeometry, solidColorBrush, null);
            d2dRenderTarget.EndDraw();

            if (File.Exists(filename))
                File.Delete(filename);

            var stream = new WICStream(wicFactory, filename, NativeFileAccess.Write);
            // Initialize a Jpeg encoder with this stream
            var encoder = new JpegBitmapEncoder(wicFactory);
            encoder.Initialize(stream);

            // Create a Frame encoder
            var bitmapFrameEncode = new BitmapFrameEncode(encoder);
            bitmapFrameEncode.Initialize();
            bitmapFrameEncode.SetSize(width, height);
            var pixelFormatGuid = SharpDX.WIC.PixelFormat.FormatDontCare;
            bitmapFrameEncode.SetPixelFormat(ref pixelFormatGuid);
            bitmapFrameEncode.WriteSource(wicBitmap);

            bitmapFrameEncode.Commit();
            encoder.Commit();

            bitmapFrameEncode.Dispose();
            encoder.Dispose();
            stream.Dispose();

            System.Diagnostics.Process.Start(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory,filename)));
        }
开发者ID:rbwhitaker,项目名称:SharpDX,代码行数:49,代码来源:Program.cs


示例12: Initialize

        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            base.Initialize(demoConfiguration);
            Factory2D = new SharpDX.Direct2D1.Factory();
            using (var surface = BackBuffer.QueryInterface<Surface>())
            {
                RenderTarget2D = new RenderTarget(Factory2D, surface,
                                                  new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            }
            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.White);
        }
开发者ID:numo16,项目名称:SharpDX,代码行数:15,代码来源:Direct2D1DemoApp.cs


示例13: Initialize

        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            Factory2D = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            HwndRenderTargetProperties properties = new HwndRenderTargetProperties();
            properties.Hwnd = DisplayHandle;
            properties.PixelSize = new SharpDX.DrawingSize(demoConfiguration.Width, demoConfiguration.Height);
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);

            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;


            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.White);
        }
开发者ID:rbwhitaker,项目名称:SharpDX,代码行数:17,代码来源:Direct2D1WinFormDemoApp.cs


示例14: InitializeGraphics

		private void InitializeGraphics()
		{
			factory = new Factory(FactoryType.SingleThreaded, DebugLevel.None);

			renderTargetProperties = new RenderTargetProperties(new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied));

			hwndRenderTargetProperties = new HwndRenderTargetProperties();
			hwndRenderTargetProperties.Hwnd = this.Handle;
			hwndRenderTargetProperties.PixelSize = new SharpDX.Size2(Width, Height);
			hwndRenderTargetProperties.PresentOptions = PresentOptions.None;

			windowRenderTarget = new WindowRenderTarget(factory, renderTargetProperties, hwndRenderTargetProperties);

			backgroundColor = new RawColor4(BackColor.R, BackColor.G, BackColor.B, BackColor.A);

			borderColor = new SolidColorBrush(windowRenderTarget, new RawColor4(0.5f, 0.5f, 0.5f, 1));
			wayColor = new SolidColorBrush(windowRenderTarget, new RawColor4(0, 0, 1, 0.3f));
			currentPositionColor = new SolidColorBrush(windowRenderTarget, new RawColor4(0, 0, 1, 1));

			graphicsInitialized = true;
		}
开发者ID:MarcusWichelmann,项目名称:StepBot,代码行数:21,代码来源:MapView.cs


示例15: DrawGlyphRun

        public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
        {
            var pathGeometry = new PathGeometry(_d2DFactory);
            var geometrySink = pathGeometry.Open();

            var fontFace = glyphRun.FontFace;
            if (glyphRun.Indices.Length > 0)
                fontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.IsSideways, glyphRun.BidiLevel % 2 != 0, geometrySink);
            geometrySink.Close();
            geometrySink.Dispose();
            fontFace.Dispose();

            var matrix = new Matrix3x2()
            {
                M11 = 1,
                M12 = 0,
                M21 = 0,
                M22 = 1,
                M31 = baselineOriginX,
                M32 = baselineOriginY
            };

            var transformedGeometry = new TransformedGeometry(_d2DFactory, pathGeometry, matrix);

            var  brushColor = (Color4)Color.Black;

            if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
                brushColor = (clientDrawingEffect as ColorDrawingEffect).Color;

            var brush = new SolidColorBrush(_renderTarget, brushColor);
            
            _renderTarget.DrawGeometry(transformedGeometry, brush);
            _renderTarget.FillGeometry(transformedGeometry, brush);

            pathGeometry.Dispose();
            transformedGeometry.Dispose();
            brush.Dispose();

            return SharpDX.Result.Ok;
        }
开发者ID:numo16,项目名称:SharpDX,代码行数:40,代码来源:CustomTextRenderer.cs


示例16: Update

        public virtual void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
        {
            context.DrawRectangle(screenSize.ApplyTo(GamesParams.Margin0.ToRectangleWith(GamesParams.Margin1)), GamesParams.ObstaclesColor, 2);

            _gameTime += dt;

            if (!_gameManager.IsTraining)
            {
                const float u = 1.00f;
                if (_gameTime < u && !AfterStartFreeze)
                {
                    var op = 1 - _gameTime / u;
                    var hideBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Colors.White,
                                                        new BrushProperties { Opacity = op });
                    context.FillRectangle(screenSize.ApplyTo(new RectangleF(0, 0, 1, 1)), hideBrush);
                }
                else
                {
                    AfterStartFreeze = true;
                }

                if (_gameTime > _gameMaxTime - u)
                {
                    var op = 1 - (_gameMaxTime - _gameTime) / u;
                    var hideBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Colors.White,
                                                        new BrushProperties { Opacity = op });
                    context.FillRectangle(screenSize.ApplyTo(new RectangleF(0, 0, 1, 1)), hideBrush);
                }

                float bar;
                bar = _gameManager.IsTraining ? 1 : _gameTime / _gameMaxTime;
                _gameManager.Page.SetTimeRectangleWidth(bar);
                _gameManager.RedrawPointsAndLifes();

                if (_gameTime > _gameMaxTime)
                    _gameManager.Win(100);
            }
        }
开发者ID:Maskl,项目名称:MetroRetro,代码行数:38,代码来源:BaseGame.cs


示例17: ToSharpDXBrush

        internal static Brush ToSharpDXBrush(RenderTarget rt, System.Drawing.Brush brush)
        {
            if (brush is System.Drawing.SolidBrush)
            {
                var res = new SolidColorBrush(rt,
                    ToSharpDXColor(((System.Drawing.SolidBrush) brush).Color));
                //res.Opacity = ToPortion(((SolidBrush) brush).Color.A);
                return res;
            }

            if (brush is System.Drawing.TextureBrush)
            {
                var tb = (TextureBrush) brush;
                var sharpDXBitmap = Converter.ToSharpDXBitmap(rt, tb.Image as System.Drawing.Bitmap, 1f);
                return new SharpDX.Direct2D1.BitmapBrush(rt, sharpDXBitmap);
            }
            throw new NotSupportedException();
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:18,代码来源:SharpDXVectorStyle.cs


示例18: InitFont

 private void InitFont()
 {
     var directWriteFactory = new SharpDX.DirectWrite.Factory();
     _directWriteTextFormat = new SharpDX.DirectWrite.TextFormat(directWriteFactory, _fontName, _fontSize) { TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading, ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near };
     _directWriteFontColor = new SharpDX.Direct2D1.SolidColorBrush(_direct2DRenderTarget, _fontColor);
     directWriteFactory.Dispose();
 }
开发者ID:chantsunman,项目名称:SharpDX_Demo,代码行数:7,代码来源:Sharp2D.cs


示例19: CreateBitmap

        private void CreateBitmap(int width, int height)
        {


            if (_bitmap == null || (_bitmap.Size.Width < width || _bitmap.Size.Height < height))
            {

                //RenderTargetProperties rtp = new RenderTargetProperties(RenderTargetType.Default,
                //    new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
                //    Factory2D.DesktopDpi.Width,
                //    Factory2D.DesktopDpi.Height,
                //    RenderTargetUsage.None,
                //    FeatureLevel.Level_DEFAULT);

                try
                {
                    var pixelFormat = SharpDX.WIC.PixelFormat.Format32bppPRGBA;
                    _bitmap = new SharpDX.WIC.Bitmap(FactoryImaging, width, height, pixelFormat, BitmapCreateCacheOption.CacheOnLoad);

                    _renderTarget = new WicRenderTarget(Factory2D, _bitmap, new RenderTargetProperties());
                    //_renderTarget = new WicRenderTarget(Factory2D, _bitmap, rtpGDI);

                    if (_brush == null)
                    {
                        _brush = new SolidColorBrush(_renderTarget, new Color4(new Color3(1, 1, 1), 1.0f));
                    }

                }
                catch (Exception exc)
                {
                    var ss = exc.Message;
                }

            }
 

        }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:37,代码来源:CCLabel-Windows.cs


示例20: Load

        /// <summary>
        /// Now that we have a CoreWindow object, the DirectX device/context can be created.
        /// </summary>
        /// <param name="entryPoint"></param>
        public void Load(string entryPoint)
        {
            // Get the default hardware device and enable debugging. Don't care about the available feature level.
            // DeviceCreationFlags.BgraSupport must be enabled to allow Direct2D interop.
            SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport);

            // Query the default device for the supported device and context interfaces.
            device = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();
            d3dContext = device.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>();

            // Query for the adapter and more advanced DXGI objects.
            SharpDX.DXGI.Device2 dxgiDevice2 = device.QueryInterface<SharpDX.DXGI.Device2>();
            SharpDX.DXGI.Adapter dxgiAdapter = dxgiDevice2.Adapter;
            SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent<SharpDX.DXGI.Factory2>();

            // Description for our swap chain settings.
            SwapChainDescription1 description = new SwapChainDescription1()
            {
                // 0 means to use automatic buffer sizing.
                Width = 0,
                Height = 0,
                // 32 bit RGBA color.
                Format = Format.B8G8R8A8_UNorm,
                // No stereo (3D) display.
                Stereo = false,
                // No multisampling.
                SampleDescription = new SampleDescription(1, 0),
                // Use the swap chain as a render target.
                Usage = Usage.RenderTargetOutput,
                // Enable double buffering to prevent flickering.
                BufferCount = 2,
                // No scaling.
                Scaling = Scaling.None,
                // Flip between both buffers.
                SwapEffect = SwapEffect.FlipSequential,
            };

            // Generate a swap chain for our window based on the specified description.
            swapChain = dxgiFactory2.CreateSwapChainForCoreWindow(device, new ComObject(window), ref description, null);

            // Get the default Direct2D device and create a context.
            SharpDX.Direct2D1.Device d2dDevice = new SharpDX.Direct2D1.Device(dxgiDevice2);
            d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);

            // Specify the properties for the bitmap that we will use as the target of our Direct2D operations.
            // We want a 32-bit BGRA surface with premultiplied alpha.
            BitmapProperties1 properties = new BitmapProperties1(new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied),
                DisplayProperties.LogicalDpi, DisplayProperties.LogicalDpi, BitmapOptions.Target | BitmapOptions.CannotDraw);

            // Get the default surface as a backbuffer and create the Bitmap1 that will hold the Direct2D drawing target.
            Surface backBuffer = swapChain.GetBackBuffer<Surface>(0);
            d2dTarget = new Bitmap1(d2dContext, backBuffer, properties);

            // Create a solid color brush.
            solidBrush = new SolidColorBrush(d2dContext, Color.Coral);

            // Create a linear gradient brush.
            // Note that the StartPoint and EndPoint values are set as absolute coordinates of the surface you are drawing to,
            // NOT the geometry we will apply the brush.
            linearGradientBrush = new LinearGradientBrush(d2dContext, new LinearGradientBrushProperties()
                {
                    StartPoint = new Vector2(50, 0),
                    EndPoint = new Vector2(450, 0),
                },
                new GradientStopCollection(d2dContext, new GradientStop[]
                    {
                        new GradientStop()
                        {
                            Color = Color.Blue,
                            Position = 0,
                        },
                        new GradientStop()
                        {
                            Color = Color.Green,
                            Position = 1,
                        }
                    }));

            // Create a radial gradient brush.
            // The center is specified in absolute coordinates, too.
            radialGradientBrush = new RadialGradientBrush(d2dContext, new RadialGradientBrushProperties()
                {
                    Center = new Vector2(250, 525),
                    RadiusX = 100,
                    RadiusY = 100,
                },
                new GradientStopCollection(d2dContext, new GradientStop[]
                {
                        new GradientStop()
                        {
                            Color = Color.Yellow,
                            Position = 0,
                        },
                        new GradientStop()
                        {
                            Color = Color.Red,
//.........这里部分代码省略.........
开发者ID:r2d2rigo,项目名称:MyFirstDirect2D-SharpDX,代码行数:101,代码来源:MyViewProvider.cs



注:本文中的SharpDX.Direct2D1.SolidColorBrush类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Direct3D11.Buffer类代码示例发布时间:2022-05-26
下一篇:
C# Direct2D1.RenderTarget类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap