示例#1
0
文件: G.cs 项目: uwx/MadSharp
        public static void FillPolygon(int[] x, int[] y, int n)
        {
            if (n < 3)
            {
                return;
            }

            var pta = new RawVector2[n - 1];

            var pta0 = new RawVector2(x[0], y[0]);

            for (var i = 1; i < n; i++)
            {
                pta[i - 1] = new RawVector2(x[i], y[i]);
            }

            using (var geo1 = new PathGeometry(Factory))
                using (var sink1 = geo1.Open())
                {
                    sink1.BeginFigure(pta0, FigureBegin);
                    sink1.AddLines(pta);
                    sink1.EndFigure(FigureEnd);
                    sink1.Close();

                    D2D.FillGeometry(geo1, _currentColor);
                }
        }
示例#2
0
		public WICBitmapCanvas (WIC.Bitmap bmp, D2D1.RenderTargetProperties properties, Direct2DFactories factories = null)
			: base (new D2D1.WicRenderTarget ((factories ?? Direct2DFactories.Shared).D2DFactory, bmp, properties), factories)
		{
			this.Bmp = bmp;
			this.scale = properties.DpiX / 96.0;
			var bmpSize = bmp.Size;
			this.size = new Size (bmpSize.Width / scale, bmpSize.Height / scale);
		}
示例#3
0
 public static void DrawMultiLineString(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IMultiLineString lines, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, Map map, float offset)
 {
     for (var i = 0; i < lines.NumGeometries; i++)
     {
         var line = (ILineString)lines[i];
         DrawLineString(renderTarget, factory, line, pen, penWidth, penStrokeStyle, map, offset);
     }
 }
示例#4
0
文件: G.cs 项目: uwx/MadSharp
 public static void DrawRoundRect(int x, int y, int wid, int hei, int arcWid, int arcHei)
 {
     D2D.DrawRoundedRectangle(new RoundedRectangle()
     {
         Rect    = new RectangleF(x, y, wid, hei),
         RadiusX = arcWid,
         RadiusY = arcHei,
     }, _currentColor);
 }
示例#5
0
文件: G.cs 项目: uwx/MadSharp
        public static void DrawImage(Image image, int x, int y, int wid, int hei)
        {
            if (image == null)
            {
                return;
            }

            D2D.DrawBitmap(image, new RectangleF(x, y, wid, hei), 1.0f,
                           BitmapInterpolationMode.NearestNeighbor);
        }
        public static D2D.Geometry ToSharpDX(this Geometry geometry, D2D.Factory factory, RectangleF rect)
        {
            var d2dGeometry = new D2D.PathGeometry(factory);

            var sink = d2dGeometry.Open();
            sink.AddGeometry(geometry, rect);
            sink.Close();

            return d2dGeometry;
        }
示例#7
0
文件: PenHandler.cs 项目: mhusen/Eto
		public sd.Brush GetBrush(sd.RenderTarget target)
		{
			if (brush == null || !ReferenceEquals(brush.Tag, target))
			{
				if (brush != null)
					brush.Dispose();
				brush = new sd.SolidColorBrush(target, Color.ToDx()) { Tag = target };
			}
			return brush;
		}
示例#8
0
文件: G.cs 项目: uwx/MadSharp
        public static void DrawImage(Image image, int x, int y)
        {
            if (image == null)
            {
                return;
            }

            D2D.DrawBitmap(image, new RectangleF(x, y, image.GetWidth(null), image.GetHeight(null)), 1.0f,
                           BitmapInterpolationMode.NearestNeighbor);
        }
			protected override sd.Brush Create(sd.RenderTarget target)
			{
				return new sd.LinearGradientBrush(
					target,
					new sd.LinearGradientBrushProperties
					{
						StartPoint = StartPoint.ToDx(),
						EndPoint = EndPoint.ToDx()
					},
					new sd.GradientStopCollection(GraphicsHandler.CurrentRenderTarget, new[] {
					new sd.GradientStop { Color = StartColor.ToDx(), Position = 0f }, 
					new sd.GradientStop { Color = EndColor.ToDx(), Position = 1f }
				}, WrapMode == GradientWrapMode.Reflect ? sd.ExtendMode.Mirror : sd.ExtendMode.Wrap)
				);
			}
示例#10
0
文件: G.cs 项目: uwx/MadSharp
        public static void DrawPolygon(int[] x, int[] y, int n)
        {
            if (n < 2)
            {
                return;
            }

            var l = n - 1;

            for (var i = 0; i < l; i++)
            {
                D2D.DrawLine(new RawVector2(x[i] - 0.5f, y[i] - 0.5f), new RawVector2(x[i + 1] - 0.5f, y[i + 1] - 0.5f), _currentColor);
            }

            D2D.DrawLine(new RawVector2(x[l] - 0.5f, y[l] - 0.5f), new RawVector2(x[0] - 0.5f, y[0] - 0.5f), _currentColor);
        }
示例#11
0
        /// <summary>
        /// Creates and pushes a D2D layer if necessary. Returns the layer or null if not required.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="renderTarget">The render target.</param>
        /// <param name="rootElement"></param>
        /// <returns></returns>
        public static D2D.Layer CreateAndPushLayerIfNecessary(this Jupiter.FrameworkElement element, D2D.RenderTarget renderTarget, Jupiter.FrameworkElement rootElement)
        {
            if (element.Opacity >= 1)
                //element.Clip == null &&
                //element.RenderTransform == null)
            {
                return null;
            }

            var layer = new D2D.Layer(renderTarget);
            var layerParameters = new D2D.LayerParameters();
            layerParameters.Opacity = (float)element.Opacity;
            layerParameters.ContentBounds = element.GetBoundingRect(rootElement).ToSharpDX();
            renderTarget.PushLayer(ref layerParameters, layer);

            return layer;
        }
示例#12
0
			protected override sd.Brush Create(sd.RenderTarget target)
			{
				return new sd.RadialGradientBrush(
					target,
					new sd.RadialGradientBrushProperties
					{ 
						Center = Center.ToDx(),
						GradientOriginOffset = (GradientOrigin - Center).ToDx(),
						RadiusX = Radius.Width,
						RadiusY = Radius.Height
					},
					new sd.GradientStopCollection(GraphicsHandler.CurrentRenderTarget, new[] {
					new sd.GradientStop { Color = StartColor.ToDx(), Position = 0f }, 
					new sd.GradientStop { Color = EndColor.ToDx(), Position = 1f }
				}, WrapMode.ToDx())
				);
			}
示例#13
0
        /// <summary>
        /// Renders a LineString to the map.
        /// </summary>
        /// <param name="renderTarget">The render target</param>
        /// <param name="factory">The factory to create shapes</param>
        /// <param name="line">LineString to render</param>
        /// <param name="pen">Pen style used for rendering</param>
        /// <param name="map">Map reference</param>
        /// <param name="offset">Offset by which line will be moved to right</param>
        public static void DrawLineString(D2D1.RenderTarget renderTarget, D2D1.Factory factory, ILineString line, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, Map map, float offset)
        {
            var points = TransformToImage(line, map);
            if (points.Length > 1)
            {
                using (var geom = new D2D1.PathGeometry(factory))
                {
                    
                    using (var gs = geom.Open())
                    {
                        gs.BeginFigure(points[0], D2D1.FigureBegin.Filled);
                        gs.AddLines(points);
                        gs.EndFigure(D2D1.FigureEnd.Open);

                        gs.Close();
                    }

                    renderTarget.DrawGeometry(geom, pen, penWidth, penStrokeStyle);
                }
            }
        }
示例#14
0
 public static void DrawLineString(D2D1.RenderTarget renderTarget, D2D1.Factory factory, ILineString line, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, Map map)
 {
     DrawLineString(renderTarget, factory, line, pen, penWidth, penStrokeStyle, map, 0);
 }
示例#15
0
		public static sd.Brush ToDx(this Brush brush, sd.RenderTarget target)
		{
			var obj = (BrushData)brush.ControlObject;
			return obj.Get(target);
		}
示例#16
0
        public static async Task<D2D.Brush> ToSharpDX(
            this Jupiter.Media.Brush brush,
            D2D.RenderTarget renderTarget,
            RectangleF rect)
        {
            if (brush == null)
                return null;

            var solidColorBrush = brush as Jupiter.Media.SolidColorBrush;

            if (solidColorBrush != null)
            {
                var color = solidColorBrush.Color.ToSharpDX();
                
                return new D2D.SolidColorBrush(
                    renderTarget,
                    color,
                    new D2D.BrushProperties
                    {
                        Opacity = (float)solidColorBrush.Opacity
                    });
            }

            var linearGradientBrush = brush as Jupiter.Media.LinearGradientBrush;

            if (linearGradientBrush != null)
            {
                var properties = new D2D.LinearGradientBrushProperties();
                //properties.StartPoint =
                //    new Vector2(
                //        (float)(linearGradientBrush.StartPoint.X * renderTarget.Size.Width),
                //        (float)(linearGradientBrush.StartPoint.Y * renderTarget.Size.Height));
                //properties.EndPoint =
                //    new Vector2(
                //        (float)(linearGradientBrush.EndPoint.X * renderTarget.Size.Width),
                //        (float)(linearGradientBrush.EndPoint.Y * renderTarget.Size.Height));
                properties.StartPoint =
                    new Vector2(
                        rect.Left + (float)(linearGradientBrush.StartPoint.X * rect.Width),
                        rect.Top + (float)(linearGradientBrush.StartPoint.Y * rect.Height));
                properties.EndPoint =
                    new Vector2(
                        rect.Left + (float)(linearGradientBrush.EndPoint.X * rect.Width),
                        rect.Top + (float)(linearGradientBrush.EndPoint.Y * rect.Height));

                var brushProperties = new D2D.BrushProperties();

                brushProperties.Opacity = (float)linearGradientBrush.Opacity;

                if (linearGradientBrush.Transform != null)
                {
                    brushProperties.Transform = linearGradientBrush.Transform.ToSharpDX();
                }

                var gradientStopCollection = linearGradientBrush.GradientStops.ToSharpDX(renderTarget);

                return new D2D.LinearGradientBrush(
                    renderTarget,
                    properties,
                    brushProperties,
                    gradientStopCollection);
            }

            var imageBrush = brush as Jupiter.Media.ImageBrush;

            if (imageBrush != null)
            {
                var bitmap = await imageBrush.ImageSource.ToSharpDX(renderTarget);

                var w = bitmap.PixelSize.Width;
                var h = bitmap.PixelSize.Height;
                Matrix3x2 transform = Matrix3x2.Identity;

                switch (imageBrush.Stretch)
                {
                    case Stretch.None:
                        transform.M31 += rect.Left + rect.Width * 0.5f - w / 2;
                        transform.M32 += rect.Top + rect.Height * 0.5f - h / 2;
                        break;
                    case Stretch.Fill:
                        transform = Matrix3x2.Scaling(
                            rect.Width / w,
                            rect.Height / h);
                        transform.M31 += rect.Left;
                        transform.M32 += rect.Top;
                        break;
                    case Stretch.Uniform:
                        var bitmapAspectRatio = (float)w / h;
                        var elementAspectRatio = rect.Width / rect.Height;

                        if (bitmapAspectRatio > elementAspectRatio)
                        {
                            var scale = rect.Width / w;
                            transform = Matrix3x2.Scaling(scale);
                            transform.M31 += rect.Left;
                            transform.M32 += rect.Top + rect.Height * 0.5f - scale * h / 2;
                        }
                        else // (elementAspectRatio >= bitmapAspectRatio)
                        {
                            var scale = rect.Height / h;
                            transform = Matrix3x2.Scaling(scale);
                            transform.M31 += rect.Left + rect.Width * 0.5f - scale * w / 2;
                            transform.M32 += rect.Top;
                        }

                        break;
                    case Stretch.UniformToFill:
                        var bitmapAspectRatio2 = (float)w / h;
                        var elementAspectRatio2 = rect.Width / rect.Height;

                        if (bitmapAspectRatio2 > elementAspectRatio2)
                        {
                            var scale = rect.Height / h;
                            transform = Matrix3x2.Scaling(scale);
                            transform.M31 += rect.Left + rect.Width * 0.5f - scale * w / 2;
                            transform.M32 += rect.Top;
                        }
                        else // (elementAspectRatio >= bitmapAspectRatio)
                        {
                            var scale = rect.Width / w;
                            transform = Matrix3x2.Scaling(scale);
                            transform.M31 += rect.Left;
                            transform.M32 += rect.Top + rect.Height * 0.5f - scale * h / 2;
                        }

                        break;
                }
                

                return new D2D.BitmapBrush1(
                    (D2D.DeviceContext)renderTarget,
                    bitmap,
                    new D2D.BitmapBrushProperties1
                    {
                        ExtendModeX = D2D.ExtendMode.Clamp,
                        ExtendModeY = D2D.ExtendMode.Clamp,
                        InterpolationMode = D2D.InterpolationMode.HighQualityCubic
                    })
                    {
                        Opacity = (float)imageBrush.Opacity,
                        Transform = transform
                    };
                //    var writeableBitmap = imageBrush.ImageSource as WriteableBitmap;
                //    var bitmapImage = imageBrush.ImageSource as BitmapImage;

                //    if (bitmapImage != null)
                //    {
                //        writeableBitmap =
                //            await WriteableBitmapFromBitmapImageExtension.FromBitmapImage(bitmapImage);
                //    }
                //    CompositionEngine c;

                //    return new D2D.BitmapBrush(
                //        renderTarget,
                //        writeableBitmap.ToSharpDX(),
                //}
            }

#if DEBUG
            throw new NotSupportedException("Only SolidColorBrush supported for now");
#else
            return new D2D.SolidColorBrush(renderTarget, Color.Transparent);
#endif
        }
示例#17
0
 public static void DrawMultiPoint(D2D1.RenderTarget renderTarget, D2D1.Factory factory,
     IMultiPoint points, D2D1.Brush brush, float size, Vector2 offset, Map map)
 {
     for (var i = 0; i < points.NumGeometries; i++)
     {
         var point = (IPoint)points[i];
         DrawPoint(renderTarget, factory, point, brush, size, offset, map);
     }
 }
示例#18
0
 private static D2D1.Bitmap CreateDefaultsymbol(D2D1.RenderTarget renderTarget)
 {
     return Converter.ToSharpDXBitmap(renderTarget, DefaultSymbol, 1f);
 }
示例#19
0
        public static void DrawPoint(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IPoint point, D2D1.Brush b, float size, Vector2 offset, Map map)
        {
            if (point == null)
                return;

            var pp = TransformToImage(point.Coordinate, map);
            if (double.IsNaN(point.X)) return;

            pp += offset;

            var e = new D2D1.Ellipse(pp, size, size);
            renderTarget.FillEllipse(e, b);
            renderTarget.DrawEllipse(e, b);
        }
        internal async Task RenderChildren(D2D.RenderTarget renderTarget, FrameworkElement rootElement, FrameworkElement fe)
        {
            var children = fe.GetChildrenByZIndex();

            foreach (var dependencyObject in children)
            {
                var child = dependencyObject as FrameworkElement;

                Debug.Assert(child != null);

                if (child != null &&
                    child.Opacity > 0 &&
                    child.Visibility == Visibility.Visible)
                {
                    await this.Render(renderTarget, rootElement, child);
                }
            }
        }
        public async Task Render(D2D.RenderTarget renderTarget, FrameworkElement rootElement, FrameworkElement fe)
        {
            var textBlock = fe as TextBlock;

            if (textBlock != null)
            {
                await TextBlockRenderer.Render(this, renderTarget, rootElement, textBlock);
                return;
            }

            var rectangle = fe as Jupiter.Shapes.Rectangle;

            if (rectangle != null)
            {
                await RectangleRenderer.Render(this, renderTarget, rootElement, rectangle);
                return;
            }

            var border = fe as Border;

            if (border != null)
            {
                await BorderRenderer.Render(this, renderTarget, rootElement, border);
                return;
            }

            var image = fe as Image;

            if (image != null)
            {
                await ImageRenderer.Render(this, renderTarget, rootElement, image);
                return;
            }

            var ellipse = fe as Ellipse;

            if (ellipse != null)
            {
#pragma warning disable 4014
                EllipseRenderer.Render(this, renderTarget, rootElement, ellipse);
#pragma warning restore 4014
                return;
            }

            var line = fe as Line;

            if (line != null)
            {
                await LineRenderer.Render(this, renderTarget, rootElement, line);
                return;
            }

            var path = fe as Jupiter.Shapes.Path;

            if (path != null)
            {
                await PathRenderer.Render(this, renderTarget, rootElement, path);
                return;
            }

            await FrameworkElementRenderer.Render(this, renderTarget, rootElement, fe);
        }
 public async Task Compose(D2D.RenderTarget renderTarget, FrameworkElement fe)
 {
     renderTarget.BeginDraw();
     renderTarget.Clear(new SharpDX.Color(0, 0, 0, 0));
     await this.Render(renderTarget, fe, fe);
     renderTarget.EndDraw();
 }
示例#23
0
		public static sd.Bitmap ToDx(this Image image, sd.RenderTarget target, Size? fittingSize = null)
		{
			if (fittingSize != null)
			{
				var icon = image as Icon;
				if (icon != null)
				{
					return icon.GetFrame(1f, fittingSize).Bitmap.ToDx(target);
				}
			}
			var handler = (ID2DBitmapHandler)image.Handler;
			return target != null ? handler.GetBitmap(target) : null;
		}
示例#24
0
 public static void DrawMultiPolygon(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IMultiPolygon pols, D2D1.Brush brush, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, bool clip, Map map)
 {
     for (var i = 0; i < pols.NumGeometries; i++)
     {
         var p = (IPolygon)pols[i];
         DrawPolygon(renderTarget, factory, p, brush, pen, penWidth, penStrokeStyle, clip, map);
     }
 }
示例#25
0
        public static void DrawPolygon(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IPolygon pol, D2D1.Brush brush, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, bool clip, Map map)
        {
            if (pol.ExteriorRing == null)
                return;

            Vector2[] points;
            var startPoint = TransformToImage(pol.ExteriorRing, map, out points);
            if (points.Length > 1)
            {
                using (var geom = new D2D1.PathGeometry(factory))
                {
                    using (var gs = geom.Open())
                    {
                        gs.SetFillMode(D2D1.FillMode.Alternate);

                        gs.BeginFigure(startPoint, D2D1.FigureBegin.Filled);
                        gs.AddLines(points);
                        gs.EndFigure(D2D1.FigureEnd.Closed);

                        for (var i = 0; i < pol.NumInteriorRings; i++)
                        {
                            startPoint = TransformToImage(pol.GetInteriorRingN(i), map, out points);
                            if (points.Length > 1)
                            {
                                gs.BeginFigure(startPoint, D2D1.FigureBegin.Filled);
                                gs.AddLines(points);
                                gs.EndFigure(D2D1.FigureEnd.Closed);
                            }
                        }

                        gs.Close();
                    }

                    if (brush != null)
                        renderTarget.FillGeometry(geom, brush);
                    if (pen != null)
                        renderTarget.DrawGeometry(geom, pen, penWidth, penStrokeStyle);
                }
            }
        }
示例#26
0
文件: G.cs 项目: uwx/MadSharp
 public static void DrawRect(int x1, int y1, int width, int height)
 {
     D2D.DrawRectangle(new RectangleF(x1, y1, width, height), _currentColor);
 }
示例#27
0
        public static void DrawPoint(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IPoint point, D2D1.Bitmap symbol, Vector2 offset,
                                     float rotation, Map map)
        {
            if (point == null)
                return;

            var pp = TransformToImage(point.Coordinate, map);
            if (double.IsNaN(pp.X)) return;
            pp += offset;

            bool symbolCreated = false;
            if (symbol == null) //We have no point style - Use a default symbol
            {
                symbol = CreateDefaultsymbol(renderTarget);
                symbolCreated = true;
            }


            lock (symbol)
            {
                if (rotation != 0 && !Single.IsNaN(rotation))
                {
                    var startingTransform = new Matrix3x2(renderTarget.Transform.ToArray());

                    var transform = renderTarget.Transform;
                    var rotationCenter = pp;
                    Matrix3x2.Rotation(rotation, rotationCenter);
                    transform *= Matrix3x2.Rotation(rotation, rotationCenter);
                    renderTarget.Transform = transform;

                    //if (symbolscale == 1f)
                    //{
                    //    g.DrawImage(symbol,  (pp.X - symbol.Width/2f + offset.X),
                    //                                (pp.Y - symbol.Height/2f + offset.Y));
                    //}
                    //else
                    //{
                    //    var width = symbol.Width*symbolscale;
                    //    var height = symbol.Height*symbolscale;
                    //    g.DrawImage(symbol, (int) pp.X - width/2 + offset.X*symbolscale,
                    //                        (int) pp.Y - height/2 + offset.Y*symbolscale, width, height);
                    //}
                    var dx = 0.5d*symbol.PixelSize.Width;
                    var dy = 0.5d*symbol.PixelSize.Height;
                    renderTarget.DrawBitmap(symbol, new SharpDX.RectangleF(Convert.ToSingle(pp.X - dx), Convert.ToSingle(pp.Y + dy),
                                                                symbol.PixelSize.Width, symbol.PixelSize.Height),
                                                                1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
                    renderTarget.Transform = startingTransform;
                }
                else
                {
                    //if (symbolscale == 1f)
                    //{
                    //    g.DrawImageUnscaled(symbol, (int) (pp.X - symbol.Width/2f + offset.X),
                    //                                (int) (pp.Y - symbol.Height/2f + offset.Y));
                    //}
                    //else
                    //{
                    //    var width = symbol.Width*symbolscale;
                    //    var height = symbol.Height*symbolscale;
                    //    g.DrawImage(symbol, (int) pp.X - width/2 + offset.X*symbolscale,
                    //                        (int) pp.Y - height/2 + offset.Y*symbolscale, width, height);
                    //}
                    var dx = 0.5d * symbol.PixelSize.Width;
                    var dy = 0.5d * symbol.PixelSize.Height;
                    renderTarget.DrawBitmap(symbol, new SharpDX.RectangleF(Convert.ToSingle(pp.X - dx), Convert.ToSingle(pp.Y + dy),
                                                                symbol.PixelSize.Width, symbol.PixelSize.Height),
                                                                1f, D2D1.BitmapInterpolationMode.Linear);
                }
            }
            if (symbolCreated)
                symbol.Dispose();
        }
示例#28
0
 public RenderTargetCanvas(D2D1.RenderTarget renderTarget, Direct2DFactories factories = null)
 {
     if (renderTarget == null)
         throw new ArgumentNullException ("renderTarget");
     this.factories = factories ?? Direct2DFactories.Shared;
     Initialize (renderTarget);
 }
示例#29
0
 public static void DrawMultiPoint(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IMultiPoint points, D2D1.Bitmap symbol, Vector2 offset,
                                   float rotation, Map map)
 {
     for (var i = 0; i < points.NumGeometries; i++)
     {
         var point = (IPoint)points[i];
         DrawPoint(renderTarget, factory, point, symbol, offset, rotation, map);
     }
 }
示例#30
0
		public static sd.Bitmap ToDx(this Image image, sd.RenderTarget target)
		{
			var handler = (ID2DBitmapHandler)image.Handler;
			return handler.GetBitmap(target);
		}
示例#31
0
文件: G.cs 项目: uwx/MadSharp
 public static void DrawString(string text, int x, int y)
 {
     D2D.DrawText(text, _textFormat, new RectangleF(x, y - _fontCached.Metrics.Height(text), 400, 400),
                  _currentColor);
 }
示例#32
0
        public static async Task<D2D.Bitmap1> ToSharpDX(this ImageSource imageSource, D2D.RenderTarget renderTarget)
        {
            var wb = imageSource as Jupiter.Media.Imaging.WriteableBitmap;

            if (wb == null)
            {
                var bi = imageSource as Jupiter.Media.Imaging.BitmapImage;

                if (bi == null)
                {
                    return null;
                }

                wb = await WriteableBitmapFromBitmapImageExtension.FromBitmapImage(bi);

                if (wb == null)
                {
                    return null;
                }
            }

            int width = wb.PixelWidth;
            int height = wb.PixelHeight;
            //var cpuReadBitmap = CompositionEngine.CreateCpuReadBitmap(width, height);
            var cpuReadBitmap = CompositionEngine.CreateRenderTargetBitmap(width, height);
            //var mappedRect = cpuReadBitmap.Map(D2D.MapOptions.Write | D2D.MapOptions.Read | D2D.MapOptions.Discard);

            using (var readStream = wb.PixelBuffer.AsStream())
            {
                var pitch = width * 4;
                //using (var writeStream =
                //    new DataStream(
                //        userBuffer: mappedRect.DataPointer,
                //        sizeInBytes: mappedRect.Pitch * height,
                //        canRead: false,
                //        canWrite: true))
                {
                    var buffer = new byte[pitch * height];
                    readStream.Read(buffer, 0, buffer.Length);
                    cpuReadBitmap.CopyFromMemory(buffer, pitch);

                    //for (int i = 0; i < height; i++)
                    //{
                    //    readStream.Read(buffer, 0, mappedRect.Pitch);
                    //    writeStream.Write(buffer, 0, buffer.Length);
                    //}
                    
                }
            }
            //cpuReadBitmap.CopyFromMemory();

            return cpuReadBitmap;
        }
示例#33
0
        private void RenderInternal(D2D1.Factory factory, D2D1.RenderTarget rt, Map map, Envelope envelope)
        {
            //if style is not enabled, we don't need to render anything
            if (!Style.Enabled)
                return;

            var geoms = GetGeometriesInView(envelope);
            if (geoms.Count == 0) return;

            var stylesToRender = GetStylesToRender(Style);

            foreach (var style in stylesToRender)
            {
                if (style is VectorStyle)
                {
                    using (var tmp = SharpDXVectorStyle.FromVectorStyle(rt, factory, (VectorStyle)style))
                    {
                        //Linestring outlines is drawn by drawing the layer once with a thicker line
                        //before drawing the "inline" on top.
                        if (tmp.EnableOutline)
                        {
                            foreach (var geom in geoms)
                            {
                                if (geom != null)
                                {
                                    //Draw background of all line-outlines first
                                    if (geom is ILineString)
                                        SharpDXVectorRenderer.DrawLineString(rt, factory, geom as ILineString, tmp.Outline, tmp.OutlineWidth, tmp.OutlineStrokeStyle, map, tmp.LineOffset);
                                    else if (geom is IMultiLineString)
                                        SharpDXVectorRenderer.DrawMultiLineString(rt, factory, geom as IMultiLineString, tmp.Outline, tmp.OutlineWidth, tmp.OutlineStrokeStyle, map, tmp.LineOffset);
                                }
                            }
                        }

                        foreach (IGeometry geom in geoms)
                        {
                            if (geom != null)
                                RenderGeometry(factory, rt, map, geom, tmp);
                        }


                    }
                }
                else
                {
                    lock(_syncRoot)
                        _logger.Debug(fmh => fmh("Not a VectorStyle!"));
                }
            }
        }
示例#34
0
        private void RenderGeometry(D2D1.Factory factory, D2D1.RenderTarget g, Map map, IGeometry feature, SharpDXVectorStyle style)
        {
            if (feature == null)
                return;

            var geometryType = feature.OgcGeometryType;
            switch (geometryType)
            {
                case OgcGeometryType.Polygon:
                    if (style.EnableOutline)
                        SharpDXVectorRenderer.DrawPolygon(g, factory, (IPolygon)feature, style.Fill, style.Outline, style.OutlineWidth, style.OutlineStrokeStyle, ClippingEnabled, map);
                    else
                        SharpDXVectorRenderer.DrawPolygon(g, factory, (IPolygon)feature, style.Fill, null, 0f, null, ClippingEnabled,  map);
                    break;
                case OgcGeometryType.MultiPolygon:
                    if (style.EnableOutline)
                        SharpDXVectorRenderer.DrawMultiPolygon(g, factory, (IMultiPolygon)feature, style.Fill, style.Outline, style.OutlineWidth, style.OutlineStrokeStyle,
                                                        ClippingEnabled, map);
                    else
                        SharpDXVectorRenderer.DrawMultiPolygon(g, factory, (IMultiPolygon)feature, style.Fill, null, 0f, null, ClippingEnabled,
                                                        map);
                    break;
                case OgcGeometryType.LineString:
                    SharpDXVectorRenderer.DrawLineString(g, factory, (ILineString)feature, style.Line, style.LineWidth, style.LineStrokeStyle, map, style.LineOffset);
                    return;
                case OgcGeometryType.MultiLineString:
                    SharpDXVectorRenderer.DrawMultiLineString(g, factory, (IMultiLineString)feature, style.Line, style.LineWidth, style.LineStrokeStyle, map, style.LineOffset);
                    break;
                case OgcGeometryType.Point:
                    if (style.Symbol != null || style.PointColor == null)
                    {
                        SharpDXVectorRenderer.DrawPoint(g, factory, (IPoint)feature, style.Symbol, style.SymbolOffset,
                                                 style.SymbolRotation, map);
                        return;
                    }
                    SharpDXVectorRenderer.DrawPoint(g, factory, (IPoint)feature, style.PointColor, style.PointSize, style.SymbolOffset, map);

                    break;
                case OgcGeometryType.MultiPoint:
                    if (style.Symbol != null || style.PointColor == null)
                    {
                        SharpDXVectorRenderer.DrawMultiPoint(g, factory, (IMultiPoint)feature, style.Symbol,
                                                  style.SymbolOffset, style.SymbolRotation, map);
                    }
                    else
                    {
                        SharpDXVectorRenderer.DrawMultiPoint(g, factory, (IMultiPoint)feature, style.PointColor, style.PointSize, style.SymbolOffset, map);
                    }
                    break;
                case OgcGeometryType.GeometryCollection:
                    var coll = (IGeometryCollection)feature;
                    for (var i = 0; i < coll.NumGeometries; i++)
                    {
                        IGeometry geom = coll[i];
                        RenderGeometry(factory, g, map, geom, style);
                    }
                    break;
                default:
                    lock (_syncRoot)
                        _logger.Debug( fmh => fmh("Unhandled geometry: {0}", feature.OgcGeometryType));
                    break;
            }
        }
示例#35
0
 public RenderTargetCanvas(DXGI.Surface surface, D2D1.RenderTargetProperties properties, Direct2DFactories factories = null)
 {
     if (surface == null)
         throw new ArgumentNullException ("surface");
     this.factories = factories ?? Direct2DFactories.Shared;
     Initialize (new D2D1.RenderTarget (this.factories.D2DFactory, surface, properties));
 }
示例#36
0
        private void RenderInternal(D2D1.Factory factory, D2D1.RenderTarget rt, Map map, 
            Envelope envelope, Rendering.Thematics.ITheme theme)
        {
            var ds = new FeatureDataSet();
            lock (_syncRoot)
            {
                DataSource.Open();
                DataSource.ExecuteIntersectionQuery(envelope, ds);
                DataSource.Close();
            }

            var scale = map.MapScale;
            var zoom = map.Zoom;

            foreach (FeatureDataTable features in ds.Tables)
            {
                // Transform geometries if necessary
                if (CoordinateTransformation != null)
                {
                    for (var i = 0; i < features.Count; i++)
                    {
                        features[i].Geometry = ToTarget(features[i].Geometry);
                    }
                }

                //Linestring outlines is drawn by drawing the layer once with a thicker line
                //before drawing the "inline" on top.
                if (Style.EnableOutline)
                {
                    for (int i = 0; i < features.Count; i++)
                    {
                        var feature = features[i];
                        var outlineStyle = theme.GetStyle(feature) as VectorStyle;
                        if (outlineStyle == null) continue;
                        if (!(outlineStyle.Enabled && outlineStyle.EnableOutline)) continue;

                        double compare = outlineStyle.VisibilityUnits == VisibilityUnits.ZoomLevel ? zoom : scale;

                        if (!(outlineStyle.MinVisible <= compare && compare <= outlineStyle.MaxVisible)) continue;

                        using (var sdxStyle = SharpDXVectorStyle.FromVectorStyle(rt, factory, outlineStyle))
                        {
                            if (sdxStyle != null)
                            {
                                //Draw background of all line-outlines first
                                if (feature.Geometry is ILineString)
                                {
                                    SharpDXVectorRenderer.DrawLineString(rt, factory, (ILineString)feature.Geometry,
                                        sdxStyle.Outline, sdxStyle.OutlineWidth, sdxStyle.OutlineStrokeStyle,
                                        map, sdxStyle.LineOffset);
                                }
                                else if (feature.Geometry is IMultiLineString)
                                {
                                    SharpDXVectorRenderer.DrawMultiLineString(rt, factory, (IMultiLineString)feature.Geometry,
                                        sdxStyle.Outline, sdxStyle.OutlineWidth, sdxStyle.OutlineStrokeStyle,
                                        map, sdxStyle.LineOffset);
                                }
                            }
                        }
                    }
                }


                var sdxVectorStyles = new Dictionary<VectorStyle, SharpDXVectorStyle>();
                for (var i = 0; i < features.Count; i++)
                {
                    var feature = features[i];
                    var style = theme.GetStyle(feature);
                    if (style == null) continue;
                    if (!style.Enabled) continue;

                    var compare = style.VisibilityUnits == VisibilityUnits.ZoomLevel ? zoom : scale;

                    if (!(style.MinVisible <= compare && compare <= style.MaxVisible)) continue;


                    IEnumerable<IStyle> stylesToRender = GetStylesToRender(style);

                    if (stylesToRender == null)
                        return;

                    foreach (var styleToRender in stylesToRender)
                    {
                        if (!styleToRender.Enabled) continue;
                        if (!(styleToRender is VectorStyle)) continue;
                        if (!(style.MinVisible <= compare && compare <= style.MaxVisible)) continue;

                        var vstyle = (VectorStyle) styleToRender;
                        SharpDXVectorStyle sdxStyle;
                        if (!sdxVectorStyles.TryGetValue(vstyle, out sdxStyle))
                        {
                            sdxStyle = SharpDXVectorStyle.FromVectorStyle(rt, factory, vstyle);
                            sdxVectorStyles.Add(vstyle, sdxStyle);
                        }

                        RenderGeometry(factory, rt, map, feature.Geometry, sdxStyle);
                    }
                }

                foreach (var value in sdxVectorStyles.Values)
                    value.Dispose();
            }
        }
示例#37
0
 protected void Initialize(D2D1.RenderTarget renderTarget)
 {
     this.renderTarget = renderTarget;
     renderTarget.BeginDraw ();
 }
示例#38
0
文件: G.cs 项目: uwx/MadSharp
 public static void DrawLine(int x1, int y1, int x2, int y2)
 {
     D2D.DrawLine(new RawVector2(x1, y1), new RawVector2(x2, y2), _currentColor);
     //throw new NotImplementedException();
 }