Ejemplo n.º 1
0
        private void DrawClippedBitmap(bool roundTop, CGBitmapContext bit, bool roundBottom)
        {
            // Clipping path for the image, different on top, middle and bottom.
            if (roundBottom)
            {
                bit.AddArc(Rad, Rad, Rad, (float)Math.PI, (float)(3 * Math.PI / 2), false);
            }
            else
            {
                bit.MoveTo(0, Rad);
                bit.AddLineToPoint(0, 0);
            }
            bit.AddLineToPoint(Dimx, 0);
            bit.AddLineToPoint(Dimx, Dimy);

            if (roundTop)
            {
                bit.AddArc(Rad, Dimy - Rad, Rad, (float)(Math.PI / 2), (float)Math.PI, false);
                bit.AddLineToPoint(0, Rad);
            }
            else
            {
                bit.AddLineToPoint(0, Dimy);
            }
            bit.Clip();
            bit.DrawImage(_rect, _scaled.CGImage);
        }
Ejemplo n.º 2
0
        public override UITableViewCell GetCell(UITableView tv)
        {
            var cell = tv.DequeueReusableCell(ikey);

            if (cell == null)
            {
                cell = new UITableViewCell(UITableViewCellStyle.Default, ikey);
            }

            if (scaled == null)
            {
                return(cell);
            }

            Section psection    = Parent as Section;
            bool    roundTop    = psection.Elements [0] == this;
            bool    roundBottom = psection.Elements [psection.Elements.Count - 1] == this;

            using (var cs = CGColorSpace.CreateDeviceRGB()){
                using (var bit = new CGBitmapContext(IntPtr.Zero, dimx, dimy, 8, 0, cs, CGImageAlphaInfo.PremultipliedFirst)){
                    if (roundBottom)
                    {
                        bit.AddArc(rad, rad, rad, (float)Math.PI, (float)(3 * Math.PI / 2), false);
                    }
                    else
                    {
                        bit.MoveTo(0, rad);
                        bit.AddLineToPoint(0, 0);
                    }
                    bit.AddLineToPoint(dimx, 0);
                    bit.AddLineToPoint(dimx, dimy);

                    if (roundTop)
                    {
                        bit.AddArc(rad, dimy - rad, rad, (float)(Math.PI / 2), (float)Math.PI, false);
                        bit.AddLineToPoint(0, rad);
                    }
                    else
                    {
                        bit.AddLineToPoint(0, dimy);
                    }
                    bit.Clip();
                    bit.DrawImage(rect, scaled.CGImage);

                    cell.ImageView.Image = UIImage.FromImage(bit.ToImage());
                }
            }
            return(cell);
        }
Ejemplo n.º 3
0
        public void UpdateRouteView()
        {
            using (var context = new CGBitmapContext(null, (int)_RouteView.Frame.Width, (int)_RouteView.Frame.Height, 8,
                                                     (int)(4 * _RouteView.Frame.Width), CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast))
            {
                context.SetStrokeColor(LineColor.CGColor);
                context.SetFillColor(0.0f, 0.0f, 1.0f, 1.0f);
                context.SetLineWidth(3.0f);

                for (int i = 0; i < _Routes.Count(); i++)
                {
                    var route = _Routes[i];
                    var point = _MapView.ConvertCoordinate(route.Coordinate, _RouteView);

                    if (i == 0)
                    {
                        context.MoveTo(point.X, _RouteView.Frame.Height - point.Y);
                    }
                    else
                    {
                        context.AddLineToPoint(point.X, _RouteView.Frame.Height - point.Y);
                    }
                }

                context.StrokePath();

                var cgImage = context.ToImage();
                var image   = UIImage.FromImage(cgImage);

                _RouteView.Image = image;
            }
        }
Ejemplo n.º 4
0
        public override void InitializeCell(UITableView tableView)
        {
            if (scaled != null)
            {
                ISection psection    = Parent as ISection;
                bool     roundTop    = psection.Elements[0] == this;
                bool     roundBottom = psection.Elements[psection.Elements.Count - 1] == this;

                using (var cs = CGColorSpace.CreateDeviceRGB())
                {
                    using (var bit = new CGBitmapContext(IntPtr.Zero, dimx, dimy, 8, 0, cs, CGImageAlphaInfo.PremultipliedFirst))
                    {
                        // Clipping path for the image, different on top, middle and bottom.
                        if (roundBottom)
                        {
                            bit.AddArc(rad, rad, rad, (float)Math.PI, (float)(3 * Math.PI / 2), false);
                        }
                        else
                        {
                            bit.MoveTo(0, rad);
                            bit.AddLineToPoint(0, 0);
                        }
                        bit.AddLineToPoint(dimx, 0);
                        bit.AddLineToPoint(dimx, dimy);

                        if (roundTop)
                        {
                            bit.AddArc(rad, dimy - rad, rad, (float)(Math.PI / 2), (float)Math.PI, false);
                            bit.AddLineToPoint(0, rad);
                        }
                        else
                        {
                            bit.AddLineToPoint(0, dimy);
                        }
                        bit.Clip();
                        bit.DrawImage(rect, scaled.CGImage);

                        Cell.ImageView.Image = UIImage.FromImage(bit.ToImage());
                    }
                }
            }
        }
Ejemplo n.º 5
0
		public override UITableViewCell GetCell (UITableView tv)
		{
			var cell = tv.DequeueReusableCell (ikey);
			if (cell == null){
				cell = new UITableViewCell (UITableViewCellStyle.Default, ikey);				
			}
			
			if (scaled == null)
				return cell;
			
			Section psection = Parent as Section;
			bool roundTop = psection.Elements [0] == this;
			bool roundBottom = psection.Elements [psection.Elements.Count-1] == this;
			
			using (var cs = CGColorSpace.CreateDeviceRGB ()){
				using (var bit = new CGBitmapContext (IntPtr.Zero, dimx, dimy, 8, 0, cs, CGImageAlphaInfo.PremultipliedFirst)){
					// Clipping path for the image, different on top, middle and bottom.
					if (roundBottom){
						bit.AddArc (rad, rad, rad, (float) Math.PI, (float) (3*Math.PI/2), false);
					} else {
						bit.MoveTo (0, rad);
						bit.AddLineToPoint (0, 0);
					}
					bit.AddLineToPoint (dimx, 0);
					bit.AddLineToPoint (dimx, dimy);
					
					if (roundTop){
						bit.AddArc (rad, dimy-rad, rad, (float) (Math.PI/2), (float) Math.PI, false);
						bit.AddLineToPoint (0, rad);
					} else {
						bit.AddLineToPoint (0, dimy);
					}
					bit.Clip ();
					bit.DrawImage (rect, scaled.CGImage);
															
					cell.ImageView.Image = UIImage.FromImage (bit.ToImage ());
					cell.TextLabel.Text = "image profile";
				}
			}
			return cell;
		}
Ejemplo n.º 6
0
        public static UIImage newImage(RectangleF rect, UIColor color)
        {
            using (var cs = CGColorSpace.CreateDeviceRGB()){
                using (var context = new CGBitmapContext(IntPtr.Zero, (int)rect.Width, (int)rect.Height, 8, (int)rect.Height * 4, cs, CGImageAlphaInfo.PremultipliedLast)){
                    rect.X      += 5;
                    rect.Y      += 5;
                    rect.Width  -= 10;
                    rect.Height -= 10;

                    color.SetColor();
                    context.MoveTo(rect.X, rect.Y);
                    context.AddLineToPoint(rect.X, rect.Height);
                    context.AddLineToPoint(rect.Width, rect.Height);
                    context.AddLineToPoint(rect.Width, rect.Y);
                    context.ClosePath();
                    context.FillPath();

                    return(UIImage.FromImage(context.ToImage()));
                }
            }
        }
Ejemplo n.º 7
0
		public override void InitializeCell(UITableView tableView)
		{
			if (_Scaled != null)
			{
				bool roundTop = Section.Elements[0] == this;
				bool roundBottom = Section.Elements[Section.Elements.Count - 1] == this;
	
				using (var cs = CGColorSpace.CreateDeviceRGB())
				{
					using (var bit = new CGBitmapContext(IntPtr.Zero, dimx, dimy, 8, 0, cs, CGImageAlphaInfo.PremultipliedFirst))
					{
						// Clipping path for the image, different on top, middle and bottom.
						if (roundBottom)
						{
							bit.AddArc(rad, rad, rad, (float)Math.PI, (float)(3 * Math.PI / 2), false);
	
						}
						else
						{
							bit.MoveTo(0, rad);
							bit.AddLineToPoint(0, 0);
						}
						bit.AddLineToPoint(dimx, 0);
						bit.AddLineToPoint(dimx, dimy);
	
						if (roundTop)
						{
							bit.AddArc(rad, dimy - rad, rad, (float)(Math.PI / 2), (float)Math.PI, false);
							bit.AddLineToPoint(0, rad);
	
						}
						else
						{
							bit.AddLineToPoint(0, dimy);
						}
						bit.Clip();
						bit.DrawImage(rect, _Scaled.CGImage);
	
						Cell.ImageView.Image = UIImage.FromImage(bit.ToImage());
					}
				}
			}
		}
Ejemplo n.º 8
0
        public static UIImage newImage(RectangleF rect,UIColor color)
        {
            using (var cs = CGColorSpace.CreateDeviceRGB ()){
                using (var context = new CGBitmapContext (IntPtr.Zero, (int)rect.Width, (int)rect.Height, 8, (int)rect.Height*4, cs, CGImageAlphaInfo.PremultipliedLast)){

                    rect.X += 5;
                    rect.Y += 5;
                    rect.Width -= 10;
                    rect.Height -= 10;

                    color.SetColor ();
                    context.MoveTo (rect.X,rect.Y);
                    context.AddLineToPoint (rect.X,rect.Height);
                    context.AddLineToPoint (rect.Width,rect.Height);
                    context.AddLineToPoint (rect.Width,rect.Y);
                    context.ClosePath ();
                    context.FillPath ();

                return UIImage.FromImage (context.ToImage());
                }
            }
        }
Ejemplo n.º 9
0
        public void UpdateRouteView()
        {
            using(var context = new CGBitmapContext(null, (int)_RouteView.Frame.Width, (int)_RouteView.Frame.Height, 8,
                (int)(4 * _RouteView.Frame.Width), CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast))
            {
                context.SetStrokeColor(LineColor.CGColor);
                context.SetFillColor(0.0f, 0.0f, 1.0f, 1.0f);
                context.SetLineWidth(3.0f);

                for (int i = 0; i < _Routes.Count(); i++)
                {
                    var route = _Routes[i];
                    var point = _MapView.ConvertCoordinate(route.Coordinate, _RouteView);

                    if(i == 0)
                        context.MoveTo(point.X, _RouteView.Frame.Height - point.Y);
                    else
                        context.AddLineToPoint(point.X, _RouteView.Frame.Height - point.Y);
                }

                context.StrokePath();

                var cgImage = context.ToImage();
                var image = UIImage.FromImage(cgImage);

                _RouteView.Image = image;
            }
        }
Ejemplo n.º 10
0
        public void DrawClock()
        {
            if (imageView.Image != null)
            {
                imageView.Image.Dispose();
            }
            if (ctx != null)
            {
                ctx.Dispose();
            }
            ctx = new CGBitmapContext(IntPtr.Zero, (int)imageView.Bounds.Width, (int)imageView.Bounds.Height, 8, 4 * (int)imageView.Bounds.Width, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst);
            GC.Collect();
            CGColor  red   = new CGColor(1f, 0f, 0f, 1f);
            CGColor  black = new CGColor(0f, 0f, 0f, 1f);
            DateTime now   = DateTime.Now;

            int big_hand_width, small_hand_width, big_square_size, small_square_size;

            if (ipad)
            {
                big_hand_width    = 16;
                small_hand_width  = 10;
                big_square_size   = 20;
                small_square_size = 10;
            }
            else
            {
                big_hand_width    = 8;
                small_hand_width  = 5;
                big_square_size   = 10;
                small_square_size = 5;
            }

            float x, y;
            int   r;
            int   sXmax = (int)imageView.Bounds.Width;
            int   sYmax = (int)imageView.Bounds.Width - big_square_size;

            int smax;

            if (sXmax <= sYmax)
            {
                smax = sXmax;
            }
            else
            {
                smax = sYmax;
            }

            int hand_max = (smax / 2) - 1;

            int sXcen = sXmax / 2;
            int sYcen = sYmax / 2;

            #region Draw circle
            for (r = 0; r < 60; r++)
            {
                x = ((float)Math.Cos(r * Math.PI / 180 * 6) * hand_max) + sXcen;
                y = ((float)Math.Sin(r * Math.PI / 180 * 6) * hand_max) + sYcen;

                switch (r)
                {
                case 0:
                case 5:
                case 10:
                case 15:
                case 20:
                case 25:
                case 30:
                case 35:
                case 40:
                case 45:
                case 50:
                case 55:
                    ctx.SetFillColorWithColor(red);
                    ctx.FillRect(new System.Drawing.RectangleF(y, x, big_square_size, big_square_size));
                    break;

                default:
                    ctx.SetFillColorWithColor(black);
                    ctx.FillRect(new System.Drawing.RectangleF(y, x, small_square_size, small_square_size));
                    break;
                }
            }
            #endregion

            #region Draw hour hand
            ctx.SetStrokeColorWithColor(black);
            float r_hour = (float)((30 * (now.Hour % 12) + now.Minute * 0.5) * (Math.PI / 180));
            ctx.MoveTo(sXcen, sYcen);
            ctx.SetLineWidth(big_hand_width);
            ctx.AddLineToPoint((float)(Math.Sin(r_hour) * (3 * hand_max / 5) + sYcen), (float)(Math.Cos(r_hour) * (3 * hand_max / 5) + sXcen));
            ctx.StrokePath();
            #endregion

            #region Draw minute hand
            ctx.SetStrokeColorWithColor(black);
            float r_minute = (float)((6 * now.Minute) * (Math.PI / 180));
            ctx.MoveTo(sXcen, sYcen);
            ctx.SetLineWidth(small_hand_width);
            ctx.AddLineToPoint((float)(Math.Sin(r_minute) * (hand_max - 5) + sYcen), (float)(Math.Cos(r_minute) * (hand_max - 5) + sXcen));
            ctx.StrokePath();
            #endregion

            #region Draw minute hand
            ctx.SetStrokeColorWithColor(red);
            float r_second = (float)((6 * now.Second) * (Math.PI / 180));
            ctx.MoveTo(sXcen, sYcen);
            ctx.SetLineWidth(5);
            ctx.AddLineToPoint((float)(Math.Sin(r_second) * (hand_max - 5) + sYcen), (float)(Math.Cos(r_second) * (hand_max - 5) + sXcen));
            ctx.StrokePath();
            #endregion

            float aclockX, aclockY, digital_timeX, digital_timeY, font_size;

            if (ipad)
            {
                font_size     = 32f;
                aclockX       = imageView.Bounds.GetMaxX() / 2 - 80;
                aclockY       = imageView.Bounds.GetMaxY() - 100;
                digital_timeX = imageView.Bounds.GetMaxX() / 2 - 70;
                digital_timeY = imageView.Bounds.GetMaxY() - 150;
            }
            else
            {
                font_size     = 16f;
                aclockX       = imageView.Bounds.GetMaxX() / 2 - 40;
                aclockY       = imageView.Bounds.GetMaxY() - 50;
                digital_timeX = imageView.Bounds.GetMaxX() / 2 - 35;
                digital_timeY = imageView.Bounds.GetMaxY() - 100;
            }


            ctx.SetFillColorWithColor(black);
            ctx.SelectFont("American Typewriter", font_size, CGTextEncoding.MacRoman);
            ctx.SetTextDrawingMode(CGTextDrawingMode.Fill);
            ctx.ShowTextAtPoint(aclockX, aclockY, ".:ACLOCK:.");

            string digital_time;

            if (now.Second % 2 == 0)
            {
                digital_time = String.Format("{0}:{1}:{2}", now.Hour.ToString("00"), now.Minute.ToString("00"), now.Second.ToString("00"));
            }
            else
            {
                digital_time = String.Format("{0} {1} {2}", now.Hour.ToString("00"), now.Minute.ToString("00"), now.Second.ToString("00"));
            }

            ctx.SetFillColorWithColor(black);
            ctx.SelectFont("American Typewriter", font_size, CGTextEncoding.MacRoman);
            ctx.SetTextDrawingMode(CGTextDrawingMode.Fill);
            ctx.ShowTextAtPoint(digital_timeX, digital_timeY, digital_time);

            imageView.Image = UIImage.FromImage(ctx.ToImage());
            ctx.Dispose();
        }