static UIImage GetAwesomeIcon(Action <CGContext> render)
        {
            // 20x20 normal, 40x40 retina
            // https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/IconsImages/IconsImages.html
            // http://tirania.org/blog/archive/2010/Jul-20-2.html
            float size = 20f;

            UIGraphics.BeginImageContextWithOptions(new CGSize(size, size), false, 0);
            using (var c = UIGraphics.GetCurrentContext()) {
                c.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
                c.SetStrokeColor(1.0f, 1.0f, 1.0f, 1.0f);
                c.TranslateCTM(3f, size - 3f);
                c.ScaleCTM(size / 1000, -size / 1000);
                render(c);
            }
            UIImage img = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(img);
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            if (!previousPoint.IsEmpty)
            {
                using (CGContext context = UIGraphics.GetCurrentContext()) {
                    context.SetStrokeColor(UIColor.Black.CGColor);
                    context.SetLineJoin(CGLineJoin.Round);
                    context.SetLineCap(CGLineCap.Round);
                    context.SetLineWidth(SignaturePad.DefaultStrokeWidth);

                    path.MoveToPoint(previousPoint);
                    path.AddLineToPoint(currentPoint);

                    context.AddPath(path);
                    context.DrawPath(CGPathDrawingMode.Stroke);
                }
            }
        }
Esempio n. 3
0
        public override void Draw(CGRect rect)
        {
            var border = (Border)Element;

            using (var context = UIGraphics.GetCurrentContext())
            {
                context.SetFillColor(border.Color.ToCGColor());
                context.SetStrokeColor(border.BorderColor.ToCGColor());
                context.SetLineWidth((float)border.BorderWidth);

                var rCorner = Bounds.Inset((int)border.BorderWidth / 2, (int)border.BorderWidth / 2);

                var radius = (nfloat)border.CornerRadius;
                radius = (nfloat)Math.Max(0, Math.Min(radius, Math.Max(rCorner.Height / 2, rCorner.Width / 2)));

                var path = CGPath.FromRoundedRect(rCorner, radius, radius);
                context.AddPath(path);
                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
Esempio n. 4
0
        private void UpdateImageViewColorFilter(UIColor color)
        {
            var image = Control.Image;

            UIGraphics.BeginImageContextWithOptions(image.Size, false, image.CurrentScale);
            var context = UIGraphics.GetCurrentContext();

            context.TranslateCTM(0, image.Size.Height);
            context.ScaleCTM(1.0f, -1.0f);
            context.SetBlendMode(CGBlendMode.Normal);
            var rect = new CGRect(0, 0, image.Size.Width, image.Size.Height);

            context.ClipToMask(rect, image.CGImage);
            context.SetFillColor(color.CGColor);
            context.FillRect(rect);
            var newImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            Control.Image = newImage;
        }
Esempio n. 5
0
        /// <summary>
        /// _chart_s the on draw pie.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void _chart_OnDrawPie(object sender, Chart.DrawEventArgs <PieDrawingData> e)
        {
            double totalDegrees = 0;

            for (int i = 0; i < e.Data.Percentages.Length; i++)
            {
                double degrees = e.Data.Percentages[i];
                using (CGContext g = UIGraphics.GetCurrentContext())
                {
                    g.SetLineWidth(2);
                    Colors[i].SetFill();
                    Colors[i].SetStroke();

                    g.AddArc((float)e.Data.X, (float)e.Data.Y, (float)e.Data.Size, (float)(Math.PI / 180 * totalDegrees), (float)(Math.PI / 180 * degrees), true);

                    g.DrawPath(CGPathDrawingMode.FillStroke);
                }
                totalDegrees += degrees;
            }
        }
Esempio n. 6
0
        protected UIImage DrawAxisDropLine()
        {
            var w      = axisDropLineWidth;
            var chartH = this.globalMoodMap.Frame.Height;
            var tickH  = tickHeight;

            UIGraphics.BeginImageContext(new SizeF(w, chartH + tickH));
            var g = UIGraphics.GetCurrentContext();

            g.SetFillColor(new CGColor(255, 255, 255, 0.1f));
            g.FillRect(new RectangleF(new PointF(0, 0), new SizeF(w, chartH)));
            g.SetFillColor(new CGColor(255, 255, 255));
            g.FillRect(new RectangleF(new PointF(0, chartH), new SizeF(w, tickH)));


            var lineImg = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(lineImg);
        }
Esempio n. 7
0
        // Prevent accidents by rounding the edges of the image
        internal static UIImage RemoveSharpEdges(UIImage image)
        {
            UIGraphics.BeginImageContext(new SizeF(48, 48));
            var c = UIGraphics.GetCurrentContext();

            c.BeginPath();
            c.MoveTo(48, 24);
            c.AddArcToPoint(48, 48, 24, 48, 4);
            c.AddArcToPoint(0, 48, 0, 24, 4);
            c.AddArcToPoint(0, 0, 24, 0, 4);
            c.AddArcToPoint(48, 0, 48, 24, 4);
            c.ClosePath();
            c.Clip();

            image.Draw(new PointF(0, 0));
            var converted = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(converted);
        }
Esempio n. 8
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            //flip the CTM so the PDF will be drawn upright
            using (CGContext g = UIGraphics.GetCurrentContext()) {
                g.TranslateCTM(0, Bounds.Height);
                g.ScaleCTM(1, -1);

                // render the first page of the PDF
                using (CGPDFPage pdfPage = pdfDoc.GetPage(1)) {
                    //get the affine transform that defines where the PDF is drawn
                    CGAffineTransform t = pdfPage.GetDrawingTransform(CGPDFBox.Crop, rect, 0, true);
                    //concatenate the pdf transform with the CTM for display in the view
                    g.ConcatCTM(t);
                    //draw the pdf page
                    g.DrawPDFPage(pdfPage);
                }
            }
        }
        public IImage GetRoundedImage(Size size, NGraphics.Color color, float radius)
        {
            size *= _scale;
            UIGraphics.BeginImageContextWithOptions(new CGSize(size.Width, size.Height), false, 0);
            IImage image = null;

            using (var context = UIGraphics.GetCurrentContext())
            {
                context.SetAllowsAntialiasing(true);
                context.SetShouldAntialias(true);

                context.SetFillColor(UIColor.FromRGBA(color.R, color.G, color.B, color.A).CGColor);
                context.AddPath(CGPath.FromRoundedRect(new CGRect(0, 0, size.Width, size.Height), radius, radius));
                context.FillPath();
            }
            var nativeImage = UIGraphics.GetImageFromCurrentImageContext();

            image = new CGImageImage(nativeImage.CGImage, _scale);
            return(image);
        }
Esempio n. 10
0
        // Child proof the image by rounding the edges of the image
        internal static UIImage RemoveSharpEdges(UIImage image)
        {
            if (image == null)
            {
                Console.WriteLine("throwing error at remove sharp edges");
                throw new ArgumentNullException("image");
            }

            UIGraphics.BeginImageContext(new CGSize(48, 48));
            var c = UIGraphics.GetCurrentContext();

            c.AddPath(smallPath);
            c.Clip();

            image.Draw(new CGRect(0, 0, 48, 48));
            var converted = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(converted);
        }
Esempio n. 11
0
        public UIImage imageWithColor(CGSize size)
        {
            var p = Element as BaseTabbedPage;

            CGRect rect = new CGRect(0, 0, size.Width, size.Height);

            UIGraphics.BeginImageContext(size);

            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                context.SetFillColor(p.TappedTabBackGround.ToCGColor());
                context.FillRect(rect);
            }

            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
Esempio n. 12
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            var gctx = UIGraphics.GetCurrentContext();

            gctx.SetFillColor(UIColor.Black.ColorWithAlpha(0.8f).CGColor);
            gctx.FillRect(rect);

            if (Radius >= 0)
            {
                gctx.SetBlendMode(CGBlendMode.Clear);
                UIColor.Clear.SetColor();

                var path = new CGPath();
                path.AddArc(Point.X, Point.Y, Radius, 0, (nfloat)(Math.PI * 2), false);
                gctx.AddPath(path);
                gctx.DrawPath(CGPathDrawingMode.Fill);
            }
        }
Esempio n. 13
0
        public static Task <UIImage> ToUIImage(this UIView view)
        {
            if (view.Superview is WrapperView wrapper)
            {
                view = wrapper;
            }

            var imageRect = new CGRect(0, 0, view.Frame.Width, view.Frame.Height);

            UIGraphics.BeginImageContext(imageRect.Size);

            var context = UIGraphics.GetCurrentContext();

            view.Layer.RenderInContext(context);
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(Task.FromResult(image));
        }
Esempio n. 14
0
        static UIImage GetIcon(string letter, float r, float g, float b, float a)
        {
            const float size = 40f;

            UIGraphics.BeginImageContextWithOptions(new SizeF(size, size), false, 0.0f);
            using (var c = UIGraphics.GetCurrentContext()) {
                c.SetFillColor(r, g, b, a);
//				GraphicsUtil.FillRoundedRect (c, new RectangleF (2, 2, size - 4, size - 4), 6);
                c.FillRect(new RectangleF(2, 2, size - 4, size - 4));
                c.SetFillColor(1, 1, 1, 1);
                c.SetStrokeColor(1, 1, 1, 1);
                UIFont font = UIFont.BoldSystemFontOfSize(size - 8);
                using (var s = new NSString(letter))
                    s.DrawString(new PointF(9f, 2f), font);
            }
            UIImage img = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(img);
        }
Esempio n. 15
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            var innerRect = rect.Inset(2.0f, TickHeight);

            UIGraphics.BeginImageContextWithOptions(innerRect.Size, false, 0);
            var context = UIGraphics.GetCurrentContext();

            var selectedSide      = GetTrackImage(innerRect, context);
            var selectedStripSide = GetTrackWithTicksImage(innerRect, context, selectedSide);

            var unselectedSide      = GetTrackImage(innerRect, context);
            var unselectedStripSide = GetTrackWithTicksImage(innerRect, context, unselectedSide);

            UIGraphics.EndImageContext();

            SetMinTrackImage(selectedStripSide, UIControlState.Normal);
            SetMaxTrackImage(unselectedStripSide, UIControlState.Normal);
        }
Esempio n. 16
0
            UIImage RenderImageWithShadow(UIImage image, float radius, UIColor color)
            {
                var size = new SizeF(image.Size.Width + 8, image.Size.Height + 8);

                BeginImageContext(size);
                var ctx = UIGraphics.GetCurrentContext();

                ctx.SaveState();
                ctx.SetShadowWithColor(new SizeF(1, 1), radius, color.CGColor);
                image.Draw(new PointF(4, 4));
                ctx.RestoreState();

                image.Draw(new PointF(4, 4));

                image = UIGraphics.GetImageFromCurrentImageContext();

                UIGraphics.EndImageContext();

                return(image);
            }
Esempio n. 17
0
        public override void Draw(RectangleF rect)
        {
            base.Draw(rect);

            CGContext context = UIGraphics.GetCurrentContext();

            CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();

            float step = 0.166666666666667f;

            float[] locations = new float[] {
                0.00f,
                step,
                step *2,
                step *3,
                step *4,
                step *5,
                1.0f
            };

            CGColor c1 = new CGColor(1, 0, 1, 1);
            CGColor c2 = new CGColor(1, 1, 0, 1);
            CGColor c3 = new CGColor(0, 1, 1, 1);

            CGColor[] colors = new CGColor[] {
                UIColor.Red.CGColor,
                c1,
                UIColor.Blue.CGColor,
                c3,
                UIColor.Green.CGColor,
                c2,
                UIColor.Red.CGColor
            };


            CGGradient gradiend = new CGGradient(colorSpace, colors, locations);

            context.DrawLinearGradient(gradiend, new PointF(rect.Size.Width, 0), new PointF(0, 0), CGGradientDrawingOptions.DrawsBeforeStartLocation);
            gradiend.Dispose();
            colorSpace.Dispose();
        }         // draw
Esempio n. 18
0
        private async Task GenerateBitmap(CancellationToken ct, string folderName, string fileName, IFrameworkElement content)
        {
            content.MinWidth  = 400;
            content.MinHeight = 400;
            (content as UIView).BackgroundColor = Colors.White;

            var size = (content as UIView).SizeThatFits(new CoreGraphics.CGSize(1024, 1024));

            if (size.Width == nfloat.NaN || size.Height == nfloat.NaN)
            {
                size = new CoreGraphics.CGSize(1024, 1024);
            }

            UIGraphics.BeginImageContextWithOptions(size, true, 0);
            var ctx = UIGraphics.GetCurrentContext();

            (content as UIView)?.Layer.RenderInContext(ctx);

            using (var img = UIGraphics.GetImageFromCurrentImageContext())
            {
                UIGraphics.EndImageContext();

                var fullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), folderName);
                var filePath = Path.Combine(fullPath, fileName);

                Directory.CreateDirectory(fullPath);

                NSError error;
                img.AsPNG().Save(filePath, true, out error);

                if (error != null)
                {
                    _log.Error(error.ToString());
                }

                if (_log.IsEnabled(LogLevel.Debug))
                {
                    _log.Debug($"Wrote screenshot to {filePath}");
                }
            }
        }
Esempio n. 19
0
        public override void Draw(CGRect rect)
        {
            using (var context = UIGraphics.GetCurrentContext()) {
                // get the scale from the context by getting the current transform matrix, then asking for
                // its "a" component, which is one of the two scale components. We could also ask for "d".
                // This assumes (safely) that the view is being scaled equally in both dimensions.
                var          scale      = context.GetCTM().xx;
                CATiledLayer tiledLayer = (CATiledLayer)this.Layer;
                var          tileSize   = tiledLayer.TileSize;

                // Even at scales lower than 100%, we are drawing into a rect in the coordinate system of the full
                // image. One tile at 50% covers the width (in original image coordinates) of two tiles at 100%.
                // So at 50% we need to stretch our tiles to double the width and height; at 25% we need to stretch
                // them to quadruple the width and height; and so on.
                // (Note that this means that we are drawing very blurry images as the scale gets low. At 12.5%,
                // our lowest scale, we are stretching about 6 small tiles to fill the entire original image area.
                // But this is okay, because the big blurry image we're drawing here will be scaled way down before
                // it is displayed.)
                tileSize.Width  /= scale;
                tileSize.Height /= scale;

                // calculate the rows and columns of tiles that intersect the rect we have been asked to draw
                int firstCol = (int)Math.Floor(rect.GetMinX() / tileSize.Width);
                int lastCol  = (int)Math.Floor((rect.GetMaxX() - 1) / tileSize.Width);
                int firstRow = (int)Math.Floor(rect.GetMinY() / tileSize.Height);
                int lastRow  = (int)Math.Floor((rect.GetMaxY() - 1) / tileSize.Height);

                for (int row = firstRow; row <= lastRow; row++)
                {
                    for (int col = firstCol; col <= lastCol; col++)
                    {
                        UIImage tile     = TileForScale((float)scale, row, col);
                        var     tileRect = new CGRect(tileSize.Width * col, tileSize.Height * row, tileSize.Width, tileSize.Height);
                        // if the tile would stick outside of our bounds, we need to truncate it so as to avoid
                        // stretching out the partial tiles at the right and bottom edges
                        tileRect.Intersect(this.Bounds);
                        tile.Draw(tileRect);
                    }
                }
            }
        }
Esempio n. 20
0
        protected override void OnElementChanged(ElementChangedEventArgs <Zumero.DataGrid.XF.DataGridBase> e)
        {
            base.OnElementChanged(e);

            // TODO if (Element)

            _container = new FivePanelsView(Element);

            Func <DataPanelView <IGraphics>, IGraphics> f = (DataPanelView <IGraphics> p) => {
                IGraphics gr = new CrossGraphics.CoreGraphics.CoreGraphicsGraphics(
                    UIGraphics.GetCurrentContext(), true, p.Bounds.Height);
                return(gr);
            };

            (Element as IDataGrid <IGraphics>).Setup(
                (IScrollablePanel <IGraphics> dg) => {
                if (dg != null)
                {
                    var p             = new ScrollableDataPanelView <IGraphics> (dg, f);
                    p.BackgroundColor = Element.BackgroundColor.ToUIColor();
                    _container.AddSubview(p);
                }
            },
                (IRegularPanel <IGraphics> dg) => {
                if (dg != null)
                {
                    var p             = new DataPanelView <IGraphics> (dg, f);
                    p.BackgroundColor = Element.BackgroundColor.ToUIColor();
                    _container.AddSubview(p);
                }
            }
                );

            if (e.OldElement != null)
            {
                e.OldElement.PropertyChanged -= OnElementPropertyChanged;
            }
            e.NewElement.PropertyChanged += OnElementPropertyChanged;

            SetNativeControl(_container);
        }
Esempio n. 21
0
        public PlatformImage CreateIcon(char icon, UIEdgeInsets insets)
        {
            getGlyphCharBuffer[0]  = icon;
            getGlyphGlyphBuffer[0] = 0;
            var ctfont = _iconAppearance.Font;

            CTFontGetGlyphsForCharacters(ctfont.Handle, getGlyphCharBuffer, getGlyphGlyphBuffer, 1);

            using (var path = ctfont.GetPathForGlyph(getGlyphGlyphBuffer[0]))
            {
                var glyphBoundingBox = ctfont.BoundingBox;
                var width            = _iconAppearance.Font.GetAdvancesForGlyphs(CTFontOrientation.Default, getGlyphGlyphBuffer);
                var height           = glyphBoundingBox.Height;
                var imageSize        = new CGSize(width + insets.Left + insets.Right, height + insets.Top + insets.Bottom);

                //NOTE: glyph bounds has negative Y origin which absolute value is equal to baseline.
                //this is why traslate and scale is used to convert context coordinates into glyph coordinates.
                var baseLineY = path.BoundingBox.Y;
                UIGraphics.BeginImageContextWithOptions(imageSize, false, 0f);
                try
                {
                    using (var context = UIGraphics.GetCurrentContext())
                    {
                        context.TranslateCTM(insets.Left, imageSize.Height + baseLineY - insets.Bottom);
                        context.ScaleCTM(1, -1);
                        path.RenderInContext(context, _iconAppearance.Colors, _iconAppearance.StrokeColor, _iconAppearance.StrokeWidth);
                        var image = UIGraphics.GetImageFromCurrentImageContext();
                        UIGraphics.EndImageContext();
                        if (image.RenderingMode != _iconAppearance.RenderingMode)
                        {
                            image = image.ImageWithRenderingMode(_iconAppearance.RenderingMode);
                        }
                        return(new PlatformImage(image));
                    }
                }
                finally
                {
                    UIGraphics.EndImageContext();
                }
            }
        }
Esempio n. 22
0
        public static UIImage DrawAnnotations(UIImage uiimage, Annotation[] annotations)
        {
            UIGraphics.BeginImageContextWithOptions(uiimage.Size, false, 0);
            var context = UIGraphics.GetCurrentContext();

            uiimage.Draw(new CGPoint());
            context.SetStrokeColor(UIColor.Red.CGColor);
            context.SetLineWidth(2);

            for (int i = 0; i < annotations.Length; i++)
            {
                float[] rects = ScaleLocation(
                    annotations[i].Rectangle,
                    (int)uiimage.Size.Width,
                    (int)uiimage.Size.Height);
                CGRect cgRect = new CGRect(
                    (nfloat)rects[0],
                    (nfloat)rects[1],
                    (nfloat)(rects[2] - rects[0]),
                    (nfloat)(rects[3] - rects[1]));
                context.AddRect(cgRect);
                context.DrawPath(CGPathDrawingMode.Stroke);
            }
            context.ScaleCTM(1, -1);
            context.TranslateCTM(0, -uiimage.Size.Height);
            for (int i = 0; i < annotations.Length; i++)
            {
                float[] rects = ScaleLocation(
                    annotations[i].Rectangle,
                    (int)uiimage.Size.Width,
                    (int)uiimage.Size.Height);
                context.SelectFont("Helvetica", 18, CGTextEncoding.MacRoman);
                context.SetFillColor((nfloat)1.0, (nfloat)0.0, (nfloat)0.0, (nfloat)1.0);
                context.SetTextDrawingMode(CGTextDrawingMode.Fill);
                context.ShowTextAtPoint(rects[0], uiimage.Size.Height - rects[1], annotations[i].Label);
            }
            UIImage imgWithRect = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(imgWithRect);
        }
Esempio n. 23
0
        public static void DrawRoundRectangle(this UIView view, RectangleF rrect, float radius, UIColor color)
        {
            var context = UIGraphics.GetCurrentContext();

            color.SetColor();

            float minx = rrect.Left;
            float midx = rrect.Left + (rrect.Width) / 2;
            float maxx = rrect.Right;
            float miny = rrect.Top;
            float midy = (rrect.Y + rrect.Size.Width) / 2;
            float maxy = rrect.Bottom;

            context.MoveTo(minx, midy);
            context.AddArcToPoint(minx, miny, midx, miny, radius);
            context.AddArcToPoint(maxx, miny, maxx, midy, radius);
            context.AddArcToPoint(maxx, maxy, midx, maxy, radius);
            context.AddArcToPoint(minx, maxy, minx, midy, radius);
            context.ClosePath();
            context.DrawPath(CGPathDrawingMode.Fill);                     // test others?
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            CGContext context = UIGraphics.GetCurrentContext();

            CGRect  bounds = rect;
            CGPoint center = new CGPoint();

            center.X = (nfloat)(bounds.Size.Width / 2.0);
            center.Y = (nfloat)(bounds.Size.Height / 2.0);

            context.SaveState();
            context.SetFillColor(UIColor.Blue.CGColor);

            context.AddArc(center.X, center.Y, _radius, 0, GetRadians(300), false);
            context.AddLineToPoint(center.X, center.Y);
            context.AddLineToPoint(rect.Width, center.Y);

            context.DrawPath(CGPathDrawingMode.Fill);
        }
Esempio n. 25
0
        /// <summary>
        /// Gets the image from view.
        /// </summary>
        /// <returns>UIImage.</returns>
        public UIImage GetImageFromView()
        {
            var rect = (RectangleF)Frame;

            UIGraphics.BeginImageContextWithOptions(rect.Size, false, 2.0f);

            CGContext context = UIGraphics.GetCurrentContext();

            if (_image != null)
            {
                context.DrawImage(Frame, _image.CGImage);
            }

            Layer.RenderInContext(context);

            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
Esempio n. 26
0
        // crop the image, without resizing
        public static UIImage CropSquareImage(UIImage sourceImage, float dimension)
        {
            var resizedImage    = MaxResizeImage(sourceImage, dimension, dimension);
            var imgSize         = resizedImage.Size;
            var largerDimension = imgSize.Width > imgSize.Height ? imgSize.Width : imgSize.Height;
            var crop_y          = largerDimension == imgSize.Width ? 0 : (largerDimension - imgSize.Width) / 2;
            var crop_x          = largerDimension == imgSize.Height ? 0 : (largerDimension - imgSize.Height) / 2;

            UIGraphics.BeginImageContext(new CGSize(dimension, dimension));
            var context     = UIGraphics.GetCurrentContext();
            var clippedRect = new CGRect(0, 0, dimension, dimension);

            context.ClipToRect(clippedRect);
            var drawRect = new CGRect(-crop_x, -crop_y, (float)imgSize.Width, (float)imgSize.Height);

            resizedImage.Draw(drawRect);
            var modifiedImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(modifiedImage);
        }
Esempio n. 27
0
        protected void SaveAsImage(object sender, System.EventArgs e)
        {
            NSError err;

            UIGraphics.BeginImageContext(this.View.Frame.Size);
            using (var context = UIGraphics.GetCurrentContext()) {
                if (context != null)
                {
                    //TODO: Save just the background and the user's drawing
                    this.View.Layer.RenderInContext(context);
                    UIImage fuckingImage = UIGraphics.GetImageFromCurrentImageContext();

                    UIGraphics.EndImageContext();
                    string location = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                    fuckingImage.AsPNG().Save(Path.Combine(location, Title + ".png"), true, out err);

                    Console.WriteLine("saved image to {0}", location);
                }
            }
        }
Esempio n. 28
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            var control = (NavigationPageGradientHeader)this.Element;

            var gradientLayer = new CAGradientLayer();

            gradientLayer.Bounds     = NavigationBar.Bounds;
            gradientLayer.Colors     = new CGColor[] { control.RightColor.ToCGColor(), control.LeftColor.ToCGColor() };
            gradientLayer.StartPoint = new CGPoint(0.0, 0.5);
            gradientLayer.EndPoint   = new CGPoint(1.0, 0.5);

            UIGraphics.BeginImageContext(gradientLayer.Bounds.Size);
            gradientLayer.RenderInContext(UIGraphics.GetCurrentContext());
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            NavigationBar.SetBackgroundImage(image, UIBarMetrics.Default);
        }
Esempio n. 29
0
            public override void Draw(RectangleF rect)
            {
                base.Draw(rect);

                var context    = UIGraphics.GetCurrentContext();
                var colorSpace = CGColorSpace.CreateDeviceRGB();

                float[] locations = { 0, 1 };

                CGColor[] colors =
                {
                    UIColor.FromRGB(0x8D, 0xCF, 0x16).CGColor,
                    UIColor.FromRGB(0x65, 0xBD, 0x10).CGColor,
                };

                var gradiend = new CGGradient(colorSpace, colors, locations);

                context.DrawLinearGradient(gradiend, new PointF(0, 0), new PointF(0, rect.Size.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
                gradiend.Dispose();
                colorSpace.Dispose();
            }
Esempio n. 30
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            //get graphics context
            using (var g = UIGraphics.GetCurrentContext())
            {
                // set up drawing attributes
                g.SetLineWidth(10.0f);
                UIColor.Green.SetFill();
                UIColor.Blue.SetStroke();

                // create geometry
                var path = new CGPath();
                path.AddArc(Bounds.GetMidX(), Bounds.GetMidY(), 50f, 0, 2.0f * (float)Math.PI, true);

                // add geometry to graphics context and draw
                g.AddPath(path);
                g.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }