private UIImage GetIconForText(string text, nuint bucketIndex)
        {
            var nsText = new NSString(text);
            var icon   = iconCache.ObjectForKey(nsText);

            if (icon != null)
            {
                return((UIImage)icon);
            }

            var font           = UIFont.BoldSystemFontOfSize(14);
            var paragraphStyle = NSParagraphStyle.Default;
            var dict           = NSDictionary.FromObjectsAndKeys(
                objects: new NSObject[] { font, paragraphStyle, options.RendererTextColor.ToUIColor() },
                keys: new NSObject[] { UIStringAttributeKey.Font, UIStringAttributeKey.ParagraphStyle, UIStringAttributeKey.ForegroundColor }
                );
            var attributes = new UIStringAttributes(dict);


            var textSize      = nsText.GetSizeUsingAttributes(attributes);
            var rectDimension = Math.Max(20, Math.Max(textSize.Width, textSize.Height)) + 3 * bucketIndex + 6;
            var rect          = new CGRect(0.0f, 0.0f, rectDimension, rectDimension);

            UIGraphics.BeginImageContext(rect.Size);
            UIGraphics.BeginImageContextWithOptions(rect.Size, false, 0);

            var ctx = UIGraphics.GetCurrentContext();

            ctx.SaveState();

            bucketIndex = (nuint)Math.Min((int)bucketIndex, options.BucketColors.Length - 1);
            var backColor = options.BucketColors[bucketIndex];

            ctx.SetFillColor(backColor.ToCGColor());
            ctx.FillEllipseInRect(rect);
            ctx.RestoreState();

            UIColor.White.SetColor();
            var textRect = rect.Inset((rect.Size.Width - textSize.Width) / 2,
                                      (rect.Size.Height - textSize.Height) / 2);

            nsText.DrawString(textRect.Integral(), attributes);

            var newImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            iconCache.SetObjectforKey(newImage, nsText);

            return(newImage);
        }
Exemple #2
0
        public static void Setup()
        {
            UIGraphics.BeginImageContext(new CoreGraphics.CGSize(1, 64f));
            Theme.PrimaryNavigationBarColor.SetFill();
            UIGraphics.RectFill(new CoreGraphics.CGRect(0, 0, 1, 64));
            var img = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;

            var navBarContainers = new [] { typeof(MenuNavigationController), typeof(ThemedNavigationController), typeof(MainNavigationController) };

            foreach (var navbarAppearance in navBarContainers.Select(x => UINavigationBar.AppearanceWhenContainedIn(x)))
            {
                navbarAppearance.TintColor       = Theme.PrimaryNavigationBarTextColor;
                navbarAppearance.BarTintColor    = Theme.PrimaryNavigationBarColor;
                navbarAppearance.BackgroundColor = Theme.PrimaryNavigationBarColor;
                navbarAppearance.SetTitleTextAttributes(new UITextAttributes {
                    TextColor = Theme.PrimaryNavigationBarTextColor, Font = UIFont.SystemFontOfSize(18f)
                });
                navbarAppearance.SetBackgroundImage(img, UIBarPosition.Any, UIBarMetrics.Default);
                navbarAppearance.BackIndicatorImage = Images.BackButton;
                navbarAppearance.BackIndicatorTransitionMaskImage = Images.BackButton;
            }

            UISegmentedControl.Appearance.TintColor = UIColor.FromRGB(110, 110, 117);
            UISegmentedControl.AppearanceWhenContainedIn(typeof(UINavigationBar)).TintColor = UIColor.White;

            UISwitch.Appearance.OnTintColor = UIColor.FromRGB(0x41, 0x83, 0xc4);

            // Composer Input Accessory Buttons
            UIButton.AppearanceWhenContainedIn(typeof(UIScrollView)).TintColor = Theme.PrimaryNavigationBarColor;

            //UITableViewHeaderFooterView.Appearance.TintColor = UIColor.FromRGB(228, 228, 228);
            var headerFooterContainers = new [] { typeof(UITableViewHeaderFooterView) };

            foreach (var navbarAppearance in headerFooterContainers)
            {
                UILabel.AppearanceWhenContainedIn(navbarAppearance).TextColor = UIColor.FromRGB(110, 110, 117);
                UILabel.AppearanceWhenContainedIn(navbarAppearance).Font      = UIFont.SystemFontOfSize(14f);
            }

            StringElement.DefaultTintColor = Theme.PrimaryNavigationBarColor;

            UIToolbar.Appearance.BarTintColor = UIColor.FromRGB(245, 245, 245);

            UIBarButtonItem.AppearanceWhenContainedIn(typeof(UISearchBar)).SetTitleTextAttributes(new UITextAttributes {
                TextColor = UIColor.White
            }, UIControlState.Normal);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            nfloat w     = View.Bounds.Width;
            nfloat h     = View.Bounds.Height;
            int    cellh = Convert.ToInt32((h - 182) / 6); //105;

            View.BackgroundColor = UIColor.White;
            UIGraphics.BeginImageContext(this.View.Frame.Size);
            UIImage i = UIImage.FromBundle("Splash");

            i = i.Scale(this.View.Frame.Size);
            View.BackgroundColor = UIColor.FromPatternImage(i);

            UITextField searchField = new UITextField
            {
                Placeholder = "Search",
                BorderStyle = UITextBorderStyle.RoundedRect,
                Frame       = new CGRect(20, 90, w - 40, 31.0f)
            };

            searchField.ShouldReturn += SearchDeals;
            View.AddSubview(searchField);

            for (int j = 0; j < Config.data._categories.Count; j++)
            {
                int y = 125 + j * cellh;

                Category c = Config.data._categories[j];

                UIButton btnCategory = UIButton.FromType(UIButtonType.Custom);
                btnCategory.Frame = new CoreGraphics.CGRect(20, y, 128, cellh);
                btnCategory.SetImage((UIImage)c.BMP, UIControlState.Normal);
                btnCategory.Tag            = Convert.ToInt32(c.ID);
                btnCategory.TouchUpInside += BtnCategory_TouchUpInside;
                View.AddSubview(btnCategory);


                UILabel lblTitle = new UILabel(new CoreGraphics.CGRect(150, y, w - 170, 34));
                lblTitle.Text = c.Name;
                View.AddSubview(lblTitle);

                if (cellh > 79)
                {
                    UILabel lblCount = new UILabel(new CoreGraphics.CGRect(150, y + 45, w - 170, 34));
                    lblCount.Text = c.Count.ToString() + " deals";
                    View.AddSubview(lblCount);
                }
            }
        }
        /// <summary>
        /// Resizes the image.
        /// </summary>
        /// <returns>The image.</returns>
        /// <param name="sourceImage">Source image.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        // resize the image (without trying to maintain aspect ratio)
        public static UIImage ResizeImage(UIImage sourceImage, float width, float height)
        {
            if (sourceImage == null)
            {
                sourceImage = UIImage.FromBundle("DefaultUser");
            }

            UIGraphics.BeginImageContext(new SizeF(width, height));
            sourceImage.Draw(new RectangleF(0, 0, width, height));
            var resultImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(resultImage);
        }
Exemple #5
0
        public static UIImage ImageFromColor(UIColor color, CoreGraphics.CGSize size)
        {
            CoreGraphics.CGRect frame = new CoreGraphics.CGRect(0, 0, size.Width, size.Height);
            UIGraphics.BeginImageContext(size);
            var context = UIGraphics.GetCurrentContext();

            context.SetFillColor(color.CGColor);
            context.FillRect(frame);

            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(image);
        }
Exemple #6
0
		UIImage GetFilteredImage (UIImage image, UIColor color)
		{
			RectangleF rect = new RectangleF (0, 0, image.Size.Width, image.Size.Height);
			UIGraphics.BeginImageContext (rect.Size);
			var context = UIGraphics.GetCurrentContext ();
			context.ClipToMask (rect, image.CGImage);
			context.SetFillColorWithColor (color.CGColor);
			context.FillRect (rect);
			UIImage img = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();
			if (img != null)
				return new UIImage (img.CGImage, 1, UIImageOrientation.DownMirrored);
			return image;
		}
Exemple #7
0
        public static UIImage ToUIImage(this UIView view)
        {
            UIGraphics.BeginImageContext(view.Frame.Size);
            var context     = UIGraphics.GetCurrentContext();
            var originFrame = view.Frame;

            view.Frame = new CGRect(new CGPoint(0, 0), view.Frame.Size);
            view.Layer.RenderInContext(context);
            view.Frame = originFrame;
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(image);
        }
        /// <summary>
        /// Captures this view into an ancillary image. This is primarily used for screen shots.
        /// </summary>
        public static UIImage Capture(this UIView view)
        {
            var rect = view.Bounds.Size;

            UIGraphics.BeginImageContext(rect);

            view.Layer.RenderInContext(UIGraphics.GetCurrentContext());

            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
Exemple #9
0
        /// <summary>
        /// Resizes an Image to a compact size.
        /// Dependent on the internal logic.
        /// </summary>
        /// <param name="image">original image</param>
        /// <returns>resized image</returns>
        public static UIImage MaxResizeImage(UIImage image)
        {
            var sourceSize      = image.Size;
            var maxResizeFactor = Math.Min(200.0 / sourceSize.Width, 200.0 / sourceSize.Height);
            var width           = maxResizeFactor * sourceSize.Width;
            var height          = maxResizeFactor * sourceSize.Height;

            UIGraphics.BeginImageContext(new CGSize(width, height));
            image.Draw(new CGRect(0, 0, width, height));
            var resultImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(resultImage);
        }
        static UIImage CreateButtonImage(CGColor color)
        {
            CGRect rect = new CGRect(0, 0, 1, 1);

            UIGraphics.BeginImageContext(rect.Size);
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetFillColor(color);
            context.FillRect(rect);
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(image);
        }
        public static UIImage ImageWithColor(UIColor color)
        {
            var rect = new CGRect(0, 0, 1, 1);

            UIGraphics.BeginImageContext(rect.Size);
            var context = UIGraphics.GetCurrentContext();

            context.SetFillColor(color.CGColor);
            context.FillRect(rect);
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(image);
        }
Exemple #12
0
        private void SetImage(string imageName, int widthRequest, int heightRequest, UIButton targetButton)
        {
            var image = UIImage.FromBundle(imageName);

            UIGraphics.BeginImageContext(new SizeF(widthRequest, heightRequest));
            image.Draw(new RectangleF(0, 0, widthRequest, heightRequest));
            var resultImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            var resizableImage = resultImage.CreateResizableImage(new UIEdgeInsets(0, 0, widthRequest, heightRequest));

            targetButton.SetImage(resizableImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal),
                                  UIControlState.Normal);
        }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            UIGraphics.BeginImageContext(View.Frame.Size);
            UIImage.FromBundle("750x1334.png").Draw(View.Bounds);
            var bgImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            var uiImageView = new UIImageView(View.Frame);

            uiImageView.Image = bgImage;
            View.AddSubview(uiImageView);
            View.SendSubviewToBack(uiImageView);
        }
Exemple #14
0
        //http://stackoverflow.com/questions/16462129/iphone-how-to-change-color-of-particular-pixel-of-a-uiimage
        public void SetPixel(Color color, int x, int y)
        {
            UIGraphics.BeginImageContext(new CGSize(Width, Height));
            var context = UIGraphics.GetCurrentContext();

            context.SaveState();
            CGRect rect = new CGRect(0f, 0f, Width, Height);

            context.DrawImage(rect, _cgImage);
            context.SetFillColor(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);
            context.FillRect(new CGRect(x, y, 1, 1));
            context.RestoreState();
            setImage(UIGraphics.GetImageFromCurrentImageContext());
        }
Exemple #15
0
        partial void btnShare_TouchUpInside(UIButton sender)
        {
            UIGraphics.BeginImageContext(View.Frame.Size);
            View.DrawViewHierarchy(View.Frame, true);
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            var shareText = string.Format("I've taken {0} steps today using #MyStepCounter!", lblStepCount.Text);
            var social    = new UIActivityViewController(new NSObject[] { new NSString(shareText), image },
                                                         new UIActivity[] { new UIActivity() });

            PresentViewController(social, true, null);
        }
        public static UIImage ToImage(this UIView view, float scale = 1.0f)
        {
            var originalRasterizationScale = view.Layer.RasterizationScale;

            try {
                UIGraphics.BeginImageContext(new SizeF(view.Bounds.Size.Width * scale, view.Bounds.Size.Height * scale));
                view.Layer.RasterizationScale = scale;
                view.Layer.RenderInContext(UIGraphics.GetCurrentContext());
                return(UIGraphics.GetImageFromCurrentImageContext());
            } finally {
                UIGraphics.EndImageContext();
                view.Layer.RasterizationScale = originalRasterizationScale;
            }
        }
Exemple #17
0
        public static UIImage Crop(UIImage image, CGRect section)
        {
            UIGraphics.BeginImageContext(section.Size);
            var context = UIGraphics.GetCurrentContext();

            context.ClipToRect(new CGRect(0, 0, section.Width, section.Height));
            var drawRectangle = new CGRect(-section.X, -section.Y, image.Size.Width, image.Size.Height);

            image.Draw(drawRectangle);
            var croppedImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(croppedImage);
        }
        //directly route to the OTP screen if the shared preference is already there
        public override async void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            UIGraphics.BeginImageContext(View.Frame.Size);
            UIImage.FromBundle("750x1334.png").Draw(View.Bounds);
            var bgImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            var uiImageView = new UIImageView(View.Frame);

            uiImageView.Image = bgImage;
            View.AddSubview(uiImageView);
            View.SendSubviewToBack(uiImageView);
            var plist = NSUserDefaults.StandardUserDefaults;

            Console.WriteLine("" + plist.StringForKey("name"));
            Console.WriteLine("" + plist.DoubleForKey("mobilenumber"));

            //for testing
            //plist.SetString("", "name");
            //plist.SetDouble(0, "mobilenumber");
            //plist.SetString("", "primaryKey");
            //plist.SetString("false", "sessionsComplete");

            if (plist.StringForKey("sessionsComplete") == "true")
            {
                PerformSegue("jumpSessionsComplete", null);
            }
            else
            {
                if (session_count < 1)
                {
                    while (session_count < 1)
                    {
                        await fetchData();
                    }
                }
                if (plist.StringForKey("name") != "" && plist.DoubleForKey("mobilenumber") > 0)
                {
                    Console.WriteLine("Hello");
                    try
                    {
                        PerformSegue("registerSuccessful", null);
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex);
                    }
                }
            }
        }
        UIImage ImageFromColor(UIColor color)
        {
            CGRect rect = new CGRect(0.0f, 0.0f, 1.0f, 1.0f);

            UIGraphics.BeginImageContext(rect.Size);
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetFillColor(color.CGColor);
            context.FillRect(rect);
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(image);
        }
Exemple #20
0
        public static UIImage MaxResizeImage(UIImage sourceImage, float percent)
        {
            var   sourceSize = sourceImage.Size;
            float width      = ((float)(percent * sourceSize.Width));
            float height     = ((float)(percent * sourceSize.Height));

            Console.WriteLine("New Height : " + height + "\n New Width : " + width);
            UIGraphics.BeginImageContext(new SizeF(width, height));
            sourceImage.Draw(new RectangleF(0, 0, width, height));
            var resultImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(resultImage);
        }
Exemple #21
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // MainNavigationController must have a black background so that the ticks
            // before the task displays don't cause a flash
            View.BackgroundColor   = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.BackgroundColor);
            View.Layer.AnchorPoint = CGPoint.Empty;
            View.Layer.Position    = CGPoint.Empty;

            DarkPanel = new UIView();
            DarkPanel.Layer.AnchorPoint = CGPoint.Empty;
            DarkPanel.Frame             = View.Frame;
            DarkPanel.Layer.Opacity     = 0.0f;
            DarkPanel.BackgroundColor   = UIColor.Black;
            View.AddSubview(DarkPanel);

            // setup the style of the nav bar
            NavigationBar.TintColor = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.TextField_PlaceholderTextColor);

            UIImage solidColor = new UIImage();

            UIGraphics.BeginImageContext(new CGSize(1, 1));
            CGContext context = UIGraphics.GetCurrentContext( );

            context.SetFillColor(Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.TopNavToolbar_BackgroundColor).CGColor);
            context.FillRect(new CGRect(0, 0, 1, 1));

            solidColor = UIGraphics.GetImageFromCurrentImageContext( );

            UIGraphics.EndImageContext( );

            NavigationBar.BarTintColor = UIColor.Clear;
            NavigationBar.SetBackgroundImage(solidColor, UIBarMetrics.Default);
            NavigationBar.Translucent = false;

            // our first (and only) child IS a ContainerViewController.
            Container = new ContainerViewController( );
            PushViewController(Container, false);

            // setup a shadow that provides depth when this panel is slid "out" from the springboard.
            ApplyEdgeShadow( );

            // setup our pan gesture
            PanGesture = new UIPanGestureRecognizer(OnPanGesture);
            PanGesture.MinimumNumberOfTouches = 1;
            PanGesture.MaximumNumberOfTouches = 1;
            View.AddGestureRecognizer(PanGesture);
        }
Exemple #22
0
        //
        // Centers image, scales and removes borders
        //
        internal static UIImage PrepareForProfileView(UIImage image)
        {
            const int size = 73;

            if (image == null)
            {
                Console.WriteLine("throwing error");
                throw new ArgumentNullException("image");
            }

            UIGraphics.BeginImageContext(new SizeF(73, 73));
            var c = UIGraphics.GetCurrentContext();

            c.AddPath(largePath);
            c.Clip();

            // Twitter not always returns squared images, adjust for that.
            var   cg     = image.CGImage;
            float width  = cg.Width;
            float height = cg.Height;

            if (width != height)
            {
                float x = 0, y = 0;
                if (width > height)
                {
                    x     = (width - height) / 2;
                    width = height;
                }
                else
                {
                    y      = (height - width) / 2;
                    height = width;
                }
                c.ScaleCTM(1, -1);
                using (var copy = cg.WithImageInRect(new RectangleF(x, y, width, height))){
                    c.DrawImage(new RectangleF(0, 0, size, -size), copy);
                }
            }
            else
            {
                image.Draw(new RectangleF(0, 0, size, size));
            }

            var converted = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(converted);
        }
        public static UIImage ToBitmap(this UIView view)
        {
            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(image);
        }
Exemple #24
0
        public static UIImage FromColor(UIColor color, CGRect rect)
        {
            UIGraphics.BeginImageContext(rect.Size);
            using (var context = UIGraphics.GetCurrentContext())
            {
                context.SetFillColor(color.CGColor);
                context.FillRect(rect);
            }

            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
        /// <summary>
        /// Creates a 1x1 image that is a certain color
        /// </summary>
        public static UIImage ToImage(this UIColor color)
        {
            try {
                UIGraphics.BeginImageContext(new CGSize(1, 1));

                using (var context = UIGraphics.GetCurrentContext()) {
                    context.SetFillColor(color.CGColor);
                    context.FillRect(new CGRect(0, 0, 1, 1));

                    return(UIGraphics.GetImageFromCurrentImageContext());
                }
            } finally {
                UIGraphics.EndImageContext();
            }
        }
Exemple #26
0
        /// <summary>
        /// Tos the local notification.
        /// </summary>
        /// <returns>The local notification.</returns>
        /// <param name="userInfo">User info.</param>
        //public static LocalNotification ToLocalNotification(this NSDictionary userInfo)
        //{
        //    var notification = new LocalNotification();
        //    if (null != userInfo && userInfo.ContainsKey(new NSString("aps")))
        //    {
        //        NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
        //        NSDictionary alert = null;
        //        if (aps.ContainsKey(new NSString("alert")))
        //            alert = aps.ObjectForKey(new NSString("alert")) as NSDictionary;
        //        if (alert != null)
        //        {
        //            notification.Title = (alert[new NSString("title")] as NSString).ToString();
        //            notification.SubTitle = (alert[new NSString("subtitle")] as NSString).ToString();
        //            notification.Message = (alert[new NSString("body")] as NSString).ToString();
        //            if (aps.ContainsKey(new NSString("badge")))
        //            {
        //                var cnt = (alert[new NSString("badge")] as NSString).ToString();
        //                notification.Badge = int.Parse(cnt);
        //            }
        //        }
        //    }
        //    return notification;
        //}
        /// <summary>
        /// Changes the color of the image.
        /// </summary>
        /// <returns>The image color.</returns>
        /// <param name="image">Image.</param>
        /// <param name="color">Color.</param>
        public static UIImage ChangeImageColor(this UIImage image, UIColor color)
        {
            var rect = new CGRect(0, 0, image.Size.Width, image.Size.Height);

            UIGraphics.BeginImageContext(rect.Size);
            var ctx = UIGraphics.GetCurrentContext();

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

            UIGraphics.EndImageContext();
            return(UIImage.FromImage(img.CGImage, 1.0f, UIImageOrientation.DownMirrored));
        }
Exemple #27
0
        public static UIImage resizeImage(UIImage image, nfloat newWidth)
        {
            nfloat scale = newWidth / image.Size.Width;

            nfloat newHeight = image.Size.Height * scale;

            UIGraphics.BeginImageContext(new CGSize(newWidth, newHeight));

            image.DrawAsPatternInRect(new CGRect(0, 0, newWidth, newHeight));
            var newImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(newImage);
        }
Exemple #28
0
        public async System.Threading.Tasks.Task <byte[]> CaptureAsync()
        {
            var view = UIApplication.SharedApplication.KeyWindow.RootViewController.View;

            UIGraphics.BeginImageContext(view.Frame.Size); view.DrawViewHierarchy(view.Frame, true);
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            using (var imageData = image.AsJPEG(100))
            {
                var bytes = new byte[imageData.Length];
                System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, bytes, 0, Convert.ToInt32(imageData.Length));
                return(bytes);
            }
        }
Exemple #29
0
        public static UIImage GetImageFromColor(this UIColor color, float height = 1)
        {
            var rect = new CGRect(0, 0, height, height);

            UIGraphics.BeginImageContext(rect.Size);
            var context = UIGraphics.GetCurrentContext();

            context.SetFillColor(color.CGColor);
            context.FillRect(rect);

            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(image);
        }
        private UIImage ResizeImage(UIImage image, nfloat marginWidth)
        {
            nfloat oldWidth    = image.Size.Width;
            nfloat scaleFactor = (marginWidth / oldWidth);

            nfloat newHeight = image.Size.Height * scaleFactor;
            nfloat newWidth  = oldWidth * scaleFactor;

            UIGraphics.BeginImageContext(new CoreGraphics.CGSize(newWidth, newHeight));
            image.Draw(new CoreGraphics.CGRect(0, 0, newWidth, newHeight));
            UIImage newImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(newImage);
        }