Ejemplo n.º 1
0
        public static UIImage MakeRoundCornerImage(UIImage img, int cornerWidth, int cornerHeight)
        {
            UIImage newImage = null;

            if (null != img)
            {
                var w = img.Size.Width;
                var h = img.Size.Height;

                CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
                CGContext    context    = new CGBitmapContext(null, (int)w, (int)h, 8, (int)(4 * w), colorSpace, CGImageAlphaInfo.PremultipliedFirst);

                context.BeginPath();
                var rect = new RectangleF(0, 0, img.Size.Width, img.Size.Height);
                AddRoundedRectToPath(context, rect, cornerWidth, cornerHeight);
                context.ClosePath();
                context.Clip();

                var cgImage = img.CGImage;
                context.DrawImage(new RectangleF(0, 0, w, h), cgImage);
                cgImage.Dispose();

                CGImage imageMasked = ((CGBitmapContext)context).ToImage();
                context.Dispose();
                colorSpace.Dispose();
                newImage = new UIImage(imageMasked);
                imageMasked.Dispose();
            }

            return(newImage);
        }
Ejemplo n.º 2
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.º 3
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.º 4
0
		public static UIImage MakeRoundCornerImage(UIImage img, int cornerWidth, int cornerHeight)
		{
			UIImage newImage = null;
			 
			if (null != img)
			{
				var w = img.Size.Width;
				var h = img.Size.Height;
				 
				CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
				CGContext context = new CGBitmapContext(null, (int)w, (int)h, 8, (int)(4 * w), colorSpace, CGImageAlphaInfo.PremultipliedFirst);
				
				context.BeginPath();
				var rect = new RectangleF(0, 0, img.Size.Width, img.Size.Height);
				AddRoundedRectToPath (context, rect, cornerWidth, cornerHeight);
				context.ClosePath();
				context.Clip();
				
				var cgImage = img.CGImage;
				context.DrawImage (new RectangleF(0, 0, w, h), cgImage);
				cgImage.Dispose();
				
				CGImage imageMasked = ((CGBitmapContext)context).ToImage();
				context.Dispose();
				colorSpace.Dispose();
				newImage = new UIImage(imageMasked);
				imageMasked.Dispose();
			}
			 
			return newImage;
		}