示例#1
0
        /// <summary>
        /// Draws a point on the target. The coordinates given are scene coordinates.
        /// </summary>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="color">Color.</param>
        /// <param name="size">Size.</param>
        protected override void DrawPoint(Target2DWrapper <global::Android.Graphics.Canvas> target, double x, double y, int color, double size)
        {
            float sizeInPixels = this.ToPixels(size) * this.Density;

            _paint.Color       = new global::Android.Graphics.Color(color);
            _paint.StrokeWidth = 1;
            _paint.SetStyle(global::Android.Graphics.Paint.Style.Fill);

            double transformedX, transformedY;

            _toViewPort.Apply(x, y, out transformedX, out transformedY);
            target.Target.DrawCircle((float)transformedX, (float)transformedY, sizeInPixels, _paint);
        }
示例#2
0
        /// <summary>
        /// Draws a line on the target. The coordinates given are scene coordinates.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="color">Color.</param>
        /// <param name="width">Width.</param>
        /// <param name="lineJoin"></param>
        /// <param name="dashes"></param>
        protected override void DrawLine(Target2DWrapper <RenderContext> target, double[] x, double[] y, int color, double width,
                                         LineJoin lineJoin, int[] dashes)
        {
            width = ToPixels(width);
            var points = new Point[x.Length];

            for (var idx = 0; idx < x.Length; idx++)
            {
                points[idx] = Tranform(x[idx], y[idx]);
            }
            target.Render().DrawLine(points, width, color.ToColor(), PenLineCap.Round, PenLineCap.Round,
                                     lineJoin.ToPenLineJoin(), dashes.ToDashStyle(0));
        }
示例#3
0
        /// <summary>
        /// Draws a point on the target. The coordinates given are scene coordinates.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="color">Color.</param>
        /// <param name="size">Size.</param>
        protected override void DrawPoint(Target2DWrapper <CGContextWrapper> target, double x, double y, int color, double size)
        {
            var transformed = this.Transform(x, y);
            var colorSimple = SimpleColor.FromArgb(color);
            var radius      = (float)(this.ToPixels(size) * _scaleFactor) / 2.0f;;

            target.Target.CGContext.SetFillColor(colorSimple.R / 256.0f, colorSimple.G / 256.0f, colorSimple.B / 256.0f,
                                                 colorSimple.A / 256.0f);
            _rectangle.X      = (float)transformed[0] - radius;
            _rectangle.Y      = (float)transformed[1] - radius;
            _rectangle.Width  = radius * 2;
            _rectangle.Height = radius * 2;
            target.Target.CGContext.FillEllipseInRect(_rectangle);
        }
示例#4
0
 /// <summary>
 /// Draws text along a line.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="text"></param>
 /// <param name="color"></param>
 /// <param name="size"></param>
 /// <param name="haloColor"></param>
 /// <param name="haloRadius"></param>
 /// <param name="fontName"></param>
 protected override void DrawLineText(Target2DWrapper <RenderContext> target, double[] x, double[] y, string text, int color,
                                      double size, int?haloColor, int?haloRadius, string fontName)
 {
     if (x.Length > 1)
     {
         size = ToPixels(size);
         var points = new Point[x.Length];
         for (var idx = 0; idx < x.Length; idx++)
         {
             points[idx] = Tranform(x[idx], y[idx]);
         }
         target.Render().DrawTextLine(text, points, new Typeface(fontName), size, color.ToColor(), haloColor.ToColor(), haloRadius);
     }
 }
示例#5
0
        /// <summary>
        /// Called right before rendering starts.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="view"></param>
        protected override void OnBeforeRender(Target2DWrapper <Graphics> target, View2D view)
        {
            //// create a bitmap and render there.
            //var bitmap = new Bitmap((int)target.Width, (int)target.Height);
            //target.BackTarget = target.Target;
            //target.BackTarget.CompositingMode = CompositingMode.SourceOver;
            //target.Target = Graphics.FromImage(bitmap);
            //target.Target.CompositingMode = CompositingMode.SourceOver;
            //target.Target.SmoothingMode = target.BackTarget.SmoothingMode;
            //target.Target.PixelOffsetMode = target.BackTarget.PixelOffsetMode;
            //target.Target.InterpolationMode = target.BackTarget.InterpolationMode;

            //target.Tag = bitmap;
        }
示例#6
0
        /// <summary>
        /// Draws text along a given line.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="color"></param>
        /// <param name="size"></param>
        /// <param name="text">Text.</param>
        protected override void DrawLineText(Target2DWrapper <global::Android.Graphics.Canvas> target, double[] xa, double[] ya, string text, int color,
                                             double size, int?haloColor, int?haloRadius, string fontName)
        {
            if (xa.Length > 1)
            {
                float sizeInPixels = this.ToPixels(size);
                _paint.SubpixelText = true;
                _paint.TextSize     = (float)sizeInPixels;
                _paint.AntiAlias    = true;

                // transform first.
                double[] xTransformed = new double[xa.Length];
                double[] yTransformed = new double[ya.Length];
                for (int idx = 0; idx < xa.Length; idx++)
                {
                    double[] transformed = this.Tranform(xa[idx], ya[idx]);
                    xTransformed [idx] = transformed [0];
                    yTransformed [idx] = transformed [1];
                }

                // get some metrics on the texts.
                float[] characterWidths = new float[text.Length];
                _paint.GetTextWidths(text, characterWidths);
//				for (int idx = 0; idx < characterWidths.Length; idx++)
//				{
//					characterWidths[idx] = _target, _view, characterWidths[idx];
//				}
                var characterHeight = (float)sizeInPixels;
                var textLength      = characterWidths.Sum();

                // calculate line length.
                var lineLength = Polyline2D.Length(xTransformed, yTransformed);
                if (lineLength > textLength * 1.2f)
                {
                    // calculate the number of labels.
                    int labelCount = (int)System.Math.Floor(lineLength / (textLength * 10)) + 1;

                    // calculate positions of label(s).
                    double positionGap = lineLength / (labelCount + 1);

                    // draw each label.
                    for (double position = positionGap; position < lineLength; position = position + positionGap)
                    {
                        this.DrawLineTextSegment(target, xTransformed, yTransformed, text, color, size, haloColor, haloRadius, position, characterWidths,
                                                 textLength, characterHeight);
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// Draws an icon unscaled but at the given scene coordinates.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="imageData"></param>
        protected override void DrawIcon(Target2DWrapper <RenderContext> target, double x, double y, byte[] imageData)
        {
            using (var stream = new MemoryStream(imageData))
            {
                var imageSource = new BitmapImage();
                imageSource.BeginInit();
                imageSource.CacheOption  = BitmapCacheOption.OnLoad;
                imageSource.StreamSource = stream;
                imageSource.EndInit();

                var leftTop = Tranform(x, y);
                leftTop.Offset(-imageSource.Width / 2, -imageSource.Height / 2);
                target.Render().DrawImage(leftTop, imageSource);
            }
        }
示例#8
0
 /// <summary>
 /// Returns the target wrapper.
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public override Target2DWrapper <global::Android.Graphics.Canvas> CreateTarget2DWrapper(global::Android.Graphics.Canvas target)
 {
     if (_wrapper == null)
     { // create the wrapper.
         _wrapper = new Target2DWrapper <global::Android.Graphics.Canvas>(
             target, target.Width, target.Height);
     }
     else
     { // updated the exist wrapper.
         _wrapper.Width  = target.Width;
         _wrapper.Height = target.Height;
         _wrapper.Target = target;
     }
     return(_wrapper);
 }
示例#9
0
        /// <summary>
        /// Draws an image.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="right"></param>
        /// <param name="bottom"></param>
        /// <param name="nativeImage"></param>
        protected override void DrawImage(Target2DWrapper <RenderContext> target, double left, double top, double right,
                                          double bottom, INativeImage nativeImage)
        {
            var wpfNativeImage = nativeImage as NativeImage;

            if (wpfNativeImage != null)
            {
                var leftTop     = Tranform(left, top);
                var rightBottom = Tranform(right, bottom);
                var width       = rightBottom.X - leftTop.X;
                var height      = rightBottom.Y - leftTop.Y;

                var destRect = new Rect(leftTop, new Size(width, height));
                target.Render().DrawImage(destRect, wpfNativeImage.Image);
            }
        }
示例#10
0
        /// <summary>
        /// Draws a line on the target. The coordinates given are scene coordinates.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="color">Color.</param>
        /// <param name="width">Width.</param>
        /// <param name="lineJoin"></param>
        /// <param name="dashes"></param>
        protected override void DrawLine(Target2DWrapper <OpenGLTarget2D> target, double[] x, double[] y, int color,
                                         double width, LineJoin lineJoin, int[] dashes)
        {
            _z = _z + 0.0001f;

            float[] points = new float[x.Length * 3];
            for (int idx = 0; idx < x.Length; idx++)
            {
                int pathIdx = idx * 3;
                points[pathIdx + 0] = (float)x[idx];
                points[pathIdx + 1] = (float)y[idx];
                points[pathIdx + 2] = _z;
            }

            _target.Target.AddLine(points, this.ToPixels(width), color);
        }
示例#11
0
        /// <summary>
        /// Draws an image on the target.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="right"></param>
        /// <param name="bottom"></param>
        /// <param name="imageData"></param>
        /// <returns>The image.</returns>
        /// <param name="tag">Tag.</param>
        protected override object DrawImage(Target2DWrapper <CGContextWrapper> target, double left, double top, double right,
                                            double bottom, byte[] imageData, object tag)
        {
            CGImage image = null;
            CGLayer layer = null;

            if (tag != null && tag is CGImage)
            {
                image = (tag as CGImage);
            }
            else if (tag != null && tag is CGLayer)
            {
                layer = (tag as CGLayer);
            }
            else
            {
                // TODO: figurate out how to use this horroble IOS api to instantiate an image from a bytearray.
                //CGImage image = CGImage.FromPNG(
            }

            if (image != null)
            { // there is an image. draw it!
                double[] topleft      = this.Tranform(left, top);
                double[] bottomright  = this.Tranform(right, bottom);
                float    leftPixels   = (float)topleft[0];
                float    topPixels    = (float)topleft[1];
                float    rightPixels  = (float)bottomright[0];
                float    bottomPixels = (float)bottomright[1];

                target.Target.CGContext.DrawImage(new RectangleF(leftPixels, topPixels, (rightPixels - leftPixels),
                                                                 (bottomPixels - topPixels)), image);
            }
            else if (layer != null)
            {
                double[] topleft      = this.Tranform(left, top);
                double[] bottomright  = this.Tranform(right, bottom);
                float    leftPixels   = (float)topleft[0];
                float    topPixels    = (float)topleft[1];
                float    rightPixels  = (float)bottomright[0];
                float    bottomPixels = (float)bottomright[1];

                target.Target.CGContext.DrawLayer(layer, new RectangleF(leftPixels, topPixels, (rightPixels - leftPixels),
                                                                        (bottomPixels - topPixels)));
            }
            return(image);
        }
示例#12
0
//		/// <summary>
//		/// Holds the bitmap cache.
//		/// </summary>
//		private global::Android.Graphics.Bitmap _cache;

        /// <summary>
        /// Called right before rendering starts.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="scenes"></param>
        /// <param name="view"></param>
        protected override void OnBeforeRender(Target2DWrapper <global::Android.Graphics.Canvas> target,
                                               List <Scene2D> scenes, View2D view)
        {
//			if (_cache == null || _cache.Width != target.Width || _cache.Height != target.Height) {
//				// create a bitmap and render there.
//				_cache = global::Android.Graphics.Bitmap.CreateBitmap ((int)target.Width, (int)target.Height,
//				                                                       global::Android.Graphics.Bitmap.Config.Argb8888);
//			} else {
//				// clear the cache???
//			}
//			target.BackTarget = target.Target;
//			target.Target = new global::Android.Graphics.Canvas(_cache);
//			target.Target.DrawColor(global::Android.Graphics.Color.Transparent);
//
//			target.Tag = _cache;
            _path = new global::Android.Graphics.Path();
        }
示例#13
0
        /// <summary>
        /// Render the specified target, projection, layers, zoomFactor and coordinate.
        /// </summary>
        /// <param name="target">Target.</param>
        /// <param name="projection">Projection.</param>
        /// <param name="layers">Layers.</param>
        /// <param name="view">View</param>
        public bool Render(TTarget target, List <ILayer> layers, View2D view)
        {
            // create the view for this control.
            Target2DWrapper <TTarget> target2DWrapper = _renderer.CreateTarget2DWrapper(target);

            // draw all layers seperatly but in the correct order.
            var scenes = new List <Scene2D>();

            for (int layerIdx = 0; layerIdx < layers.Count; layerIdx++)
            {
                // get the layer.
                scenes.Add(layers[layerIdx].Scene);
            }

            // render the scenes.
            return(_renderer.Render(target, scenes, view));
        }
示例#14
0
        /// <summary>
        /// Draws text along a line.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="text"></param>
        /// <param name="color"></param>
        /// <param name="size"></param>
        /// <param name="haloColor"></param>
        /// <param name="haloRadius"></param>
        /// <param name="fontName"></param>
        protected override void DrawLineText(Target2DWrapper <Graphics> target, double[] x, double[] y, string text, int color,
                                             double size, int?haloColor, int?haloRadius, string fontName)
        {
            if (x.Length > 1)
            {
                float sizeInPixels = this.ToPixels(size);
                Color textColor    = Color.FromArgb(color);
                Brush brush        = new SolidBrush(textColor);
                Brush haloBrush    = null;
                if (haloColor.HasValue && haloRadius.HasValue && haloRadius.Value > 0)
                {
                    haloBrush = new SolidBrush(Color.FromArgb(haloColor.Value));
                }
                Font font = new Font(FontFamily.GenericSansSerif, sizeInPixels);

                // get some metrics on the texts.
                var characterWidths = GetCharacterWidths(target.Target, text, font);
                for (int idx = 0; idx < characterWidths.Length; idx++)
                {
                    characterWidths[idx] = (float)this.FromPixels(_target, _view, characterWidths[idx]);
                }
                var characterHeight = target.Target.MeasureString(text, font).Height;
                var textLength      = characterWidths.Sum();
//                var avgCharacterWidth = textLength / characterWidths.Length;

                // calculate line length.
                var lineLength = Polyline2D.Length(x, y);
                if (lineLength > textLength * 1.1f)
                {
                    // calculate the number of labels.
                    int labelCount = (int)System.Math.Floor(lineLength / (textLength * 10)) + 1;

                    // calculate positions of label(s).
                    double positionGap = lineLength / (labelCount + 1);

                    // draw each label.
                    for (double position = positionGap; position < lineLength; position = position + positionGap)
                    {
                        this.DrawLineTextSegment(target, x, y, text, color, size, haloColor, haloRadius, position, characterWidths,
                                                 textLength, font, characterHeight, haloBrush, brush);
                    }
                }
            }
        }
示例#15
0
        /// <summary>
        /// Draws an icon on the target unscaled but centered at the given scene coordinates.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="imageData"></param>
        protected override void DrawIcon(Target2DWrapper <global::Android.Graphics.Canvas> target, double x, double y,
                                         byte[] imageData)
        {
            global::Android.Graphics.Bitmap image = global::Android.Graphics.BitmapFactory.DecodeByteArray(
                imageData, 0, imageData.Length);

//			// calculate target rectangle.
//			double sceneSizeX = this.FromPixels(target, _view, image.Width) / 2.0f;
//			double sceneSizeY = this.FromPixels(target, _view, image.Height) / 2.0f;
//			double sceneTop = x + sceneSizeX;
//			double sceneBottom = x - sceneSizeX;
//			double sceneLeft = y - sceneSizeY;
//			double sceneRight = y + sceneSizeY;

            double[] transformed = this.Tranform(x, y);

            target.Target.DrawBitmap(image, (float)transformed [0], (float)transformed [1], null);
            image.Dispose();
        }
示例#16
0
        /// <summary>
        /// Builds the cached scene.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="currentCache"></param>
        /// <param name="currentScenes"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        protected override Scene2D BuildSceneCache(Target2DWrapper <Graphics> target, Scene2D currentCache,
                                                   List <Scene2D> currentScenes, View2D view)
        {
            var scene = new Scene2DSimple();

//            scene.BackColor = currentScenes[0].BackColor;
//
//	        var bitmap = target.Tag as Bitmap;
//	        if (bitmap != null)
//	        {
//
//				// build the boundingbox.
//				var viewBox = view.OuterBox;
//				var box = new GeoCoordinateBox (map.Projection.ToGeoCoordinates (viewBox.Min [0], viewBox.Min [1]),
//				                                map.Projection.ToGeoCoordinates (viewBox.Max [0], viewBox.Max [1]));
//
//	            scene.AddImage(0, float.MinValue, float.MaxValue,
//                    view.Left, view.Top, view.Right, view.Bottom, new byte[0], bitmap);
//	        }
            return(scene);
        }
示例#17
0
        /// <summary>
        /// Draws an image on the target.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="right"></param>
        /// <param name="bottom"></param>
        /// <param name="nativeImage"></param>
        /// <returns>The image.</returns>
        protected override void DrawImage(Target2DWrapper <CGContextWrapper> target, double left, double top, double right,
                                          double bottom, INativeImage nativeImage)
        {
            // get the native image.
            var iosNativeImage = (nativeImage as NativeImage);

            // get CGImage.
            CGImage image = iosNativeImage.Image;

            var bounds = new RectangleF2D(left, bottom, (left - right),
                                          (top - bottom));

            target.Target.CGContext.SetAllowsFontSubpixelQuantization(true);
            target.Target.CGContext.SetAllowsFontSmoothing(true);
            target.Target.CGContext.SetAllowsAntialiasing(true);
            target.Target.CGContext.SetAllowsSubpixelPositioning(true);
            target.Target.CGContext.SetShouldAntialias(true);

            PointF2D bottomLeft  = new PointF2D(this.Transform(bounds.BottomLeft[0], bounds.BottomLeft[1]));
            PointF2D bottomRight = new PointF2D(this.Transform(bounds.BottomRight[0], bounds.BottomRight[1]));
            PointF2D topLeft     = new PointF2D(this.Transform(bounds.TopLeft[0], bounds.TopLeft[1]));
            //PointF2D topRight = new PointF2D(this.Tranform (bounds.TopRight [0], bounds.TopRight [1]));

            RectangleF2D transformed = new RectangleF2D(bottomLeft, bottomLeft.Distance(bottomRight), bottomLeft.Distance(topLeft),
                                                        topLeft - bottomLeft);

            target.Target.CGContext.SaveState();
            target.Target.CGContext.TranslateCTM((float)transformed.BottomLeft[0], (float)transformed.BottomLeft[1]);
            target.Target.CGContext.RotateCTM(-(float)((Radian)transformed.Angle).Value);
            target.Target.CGContext.ScaleCTM(-1, 1);

            // build rectangle.
            _rectangle.X      = 0;
            _rectangle.Y      = 0;
            _rectangle.Width  = (float)transformed.Width;
            _rectangle.Height = (float)transformed.Height;
            target.Target.CGContext.DrawImage(_rectangle, image);

            target.Target.CGContext.RestoreState();
        }
示例#18
0
        /// <summary>
        /// Draws an image.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="right"></param>
        /// <param name="bottom"></param>
        /// <param name="imageData"></param>
        /// <param name="tag"></param>
        protected override object DrawImage(Target2DWrapper <Graphics> target, double left, double top, double right,
                                            double bottom, byte[] imageData, object tag)
        {
            // get the image.
            var image = (tag as Image);

            if (image == null)
            {
                image = Image.FromStream(new MemoryStream(imageData));
            }

            double[] topleft     = this.Tranform(left, top);
            double[] bottomright = this.Tranform(right, bottom);
            float    x           = (float)topleft[0];
            float    y           = (float)topleft[1];
            float    width       = (float)bottomright[0] - x;
            float    height      = (float)bottomright[1] - y;

            target.Target.DrawImage(image, new RectangleF(x, y,
                                                          width, height));
            return(image);
        }
示例#19
0
        /// <summary>
        /// Builds the cached scene.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="currentCache"></param>
        /// <param name="currentScenes"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        protected override Scene2D BuildSceneCache(Target2DWrapper <global::Android.Graphics.Canvas> target, Scene2D currentCache,
                                                   List <Scene2D> currentScenes, View2D view)
        {
            var scene = new Scene2DSimple();

//			scene.BackColor = currentScenes[0].BackColor;
//
//			var bitmap = target.Tag as global::Android.Graphics.Bitmap;
//			if (bitmap != null)
//			{
//				byte[] imageData = null;
//				using (var stream = new MemoryStream())
//				{
//					bitmap.Compress(global::Android.Graphics.Bitmap.CompressFormat.Png, 0, stream);
//
//					imageData = stream.ToArray();
//				}
//				scene.AddImage(0, float.MinValue, float.MaxValue,
//				               view.Left, view.Top, view.Right, view.Bottom, imageData);
//			}
            return(scene);
        }
示例#20
0
        /// <summary>
        /// Draws a polygon on the target. The coordinates given are scene coordinates.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="color">Color.</param>
        /// <param name="width">Width.</param>
        /// <param name="fill">If set to <c>true</c> fill.</param>
        protected override void DrawPolygon(Target2DWrapper <Graphics> target, double[] x, double[] y, int color,
                                            double width, bool fill)
        {
            float widthInPixels = this.ToPixels(width);

            var points = new PointF[x.Length];

            for (int idx = 0; idx < x.Length; idx++)
            {
                double[] transformed = this.Tranform(x[idx], y[idx]);
                points[idx] = new PointF((float)transformed[0], (float)transformed[1]);
            }
            if (fill)
            {
//                var pen = new Pen(Color.FromArgb(color), widthInPixels);
                target.Target.FillPolygon(new SolidBrush(Color.FromArgb(color)), points);
            }
            else
            {
                var pen = new Pen(Color.FromArgb(color), widthInPixels);
                target.Target.DrawPolygon(pen, points);
            }
        }
示例#21
0
        /// <summary>
        /// Draws an image on the target.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="right"></param>
        /// <param name="bottom"></param>
        /// <param name="imageData"></param>
        /// <param name="tag"></param>
        protected override object DrawImage(Target2DWrapper <global::Android.Graphics.Canvas> target,
                                            double left, double top, double right, double bottom, byte[] imageData,
                                            object tag)
        {
            global::Android.Graphics.Bitmap image = (tag as global::Android.Graphics.Bitmap);
            if (image == null)
            {
                image = global::Android.Graphics.BitmapFactory.DecodeByteArray(
                    imageData, 0, imageData.Length);
            }

            double[] topleft      = this.Tranform(left, top);
            double[] bottomright  = this.Tranform(right, bottom);
            float    leftPixels   = (float)topleft[0];
            float    topPixels    = (float)topleft[1];
            float    rightPixels  = (float)bottomright[0];
            float    bottomPixels = (float)bottomright[1];

            target.Target.DrawBitmap(image, new global::Android.Graphics.Rect(0, 0, image.Width, image.Height),
                                     new global::Android.Graphics.RectF(leftPixels, topPixels, rightPixels, bottomPixels),
                                     null);
            return(image);
        }
示例#22
0
        /// <summary>
        /// Draws the image.
        /// </summary>
        /// <returns>The image.</returns>
        /// <param name="target">Target.</param>
        /// <param name="bounds">Bounds.</param>
        /// <param name="nativeImage">Image data.</param>
        protected override void DrawImage(Target2DWrapper <Canvas> target, RectangleF2D bounds, INativeImage nativeImage)
        {
            double transformed1_0, transformed1_1;
            var    nativeAndroidImage = (nativeImage as NativeImage);

            global::Android.Graphics.Bitmap image = nativeAndroidImage.Image;
            // this.Transform(bounds.BottomLeft[0], bounds.BottomLeft[1], _transformed1);
            _toViewPort.Apply(bounds.BottomLeft[0], bounds.BottomLeft[1], out transformed1_0, out transformed1_1);
            var bottomLeft = new PointF2D(transformed1_0, transformed1_1);

            // this.Transform(bounds.BottomRight[0], bounds.BottomRight[1], _transformed1);
            _toViewPort.Apply(bounds.BottomRight[0], bounds.BottomRight[1], out transformed1_0, out transformed1_1);
            var bottomRight = new PointF2D(transformed1_0, transformed1_1);

            // this.Transform(bounds.TopLeft[0], bounds.TopLeft[1], _transformed1);
            _toViewPort.Apply(bounds.TopLeft[0], bounds.TopLeft[1], out transformed1_0, out transformed1_1);
            var topLeft = new PointF2D(transformed1_0, transformed1_1);
            //PointF2D topRight = new PointF2D(this.Tranform (bounds.TopRight [0], bounds.TopRight [1]));

            var transformed = new RectangleF2D(bottomLeft, bottomLeft.Distance(bottomRight), bottomLeft.Distance(topLeft),
                                               topLeft - bottomLeft);

            _paint.AntiAlias    = true;
            _paint.FilterBitmap = true;
            target.Target.Save();
            target.Target.Translate((float)transformed.BottomLeft [0], (float)transformed.BottomLeft [1]);
            target.Target.Rotate(-(float)((Degree)transformed.Angle).Value);
            if (image != null)
            {
                target.Target.DrawBitmap(image,
                                         new global::Android.Graphics.Rect(0, 0, image.Width, image.Height),
                                         new global::Android.Graphics.RectF(0, 0, (float)transformed.Width, (float)transformed.Height),
                                         _paint);
            }
            target.Target.Restore();
        }
示例#23
0
 public static void CloseRender(this Target2DWrapper <RenderContext> target)
 {
     target.Target.CloseDrawingContext();
 }
示例#24
0
 public static DrawingContext Render(this Target2DWrapper <RenderContext> target)
 {
     return(target.Target.GetDrawingContext());
 }
示例#25
0
 public static void OpenRender(this Target2DWrapper <RenderContext> target)
 {
     target.Target.OpenDrawingContext();
 }
示例#26
0
        protected override double FromPixels(Target2DWrapper <OpenGLTarget2D> target, View2D view, double sizeInPixels)
        {
            double scaleX = target.Width / view.Width;

            return(sizeInPixels / scaleX);
        }
示例#27
0
 protected override void DrawLineText(Target2DWrapper <OpenGLTarget2D> target, double[] x, double[] y, string text, int color,
                                      double size, int?haloColor, int?haloRadius, string fontName)
 {
 }
示例#28
0
 protected override void DrawImage(Target2DWrapper <OpenGLTarget2D> target, OsmSharp.Math.Primitives.RectangleF2D bounds, INativeImage tag)
 {
 }
示例#29
0
 protected override void DrawImage(Target2DWrapper <OpenGLTarget2D> target, double left, double top, double right, double bottom, INativeImage tag)
 {
 }
示例#30
0
 protected override void DrawIcon(Target2DWrapper <OpenGLTarget2D> target, double x, double y, byte[] imageData)
 {
 }