Exemplo n.º 1
0
        public static UIImage Blur(this UIImage image, float radius)
        {
            if (image == null)
                return image;
            try
            {
                var imageToBlur = CIImage.FromCGImage(image.CGImage);

                if(imageToBlur == null)
                    return image;
                var transform = new CIAffineClamp();
                transform.Transform = CGAffineTransform.MakeIdentity();
                transform.Image = imageToBlur;

                var gaussianBlurFilter = new CIGaussianBlur();

                gaussianBlurFilter.Image = transform.OutputImage;
                gaussianBlurFilter.Radius = radius;
                if (context == null)
                    context = CIContext.FromOptions(null);

                var resultImage = gaussianBlurFilter.OutputImage;

                var finalImage = UIImage.FromImage(context.CreateCGImage(resultImage, new RectangleF(PointF.Empty, image.Size)), 1, UIImageOrientation.Up);
                return finalImage;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return image;
            }
        }
Exemplo n.º 2
0
        public static UIImage Blur(this UIImage image, float radius)
        {
            try
            {
                var imageToBlur = CIImage.FromCGImage(image.CGImage);

                var transform = new CIAffineClamp();
                transform.Transform = CGAffineTransform.MakeIdentity();
                transform.Image     = imageToBlur;


                var gaussianBlurFilter = new CIGaussianBlur();

                gaussianBlurFilter.Image  = transform.OutputImage;
                gaussianBlurFilter.Radius = radius;
                if (context == null)
                {
                    context = CIContext.FromOptions(null);
                }

                var resultImage = gaussianBlurFilter.OutputImage;

                var finalImage = UIImage.FromImage(
                    context.CreateCGImage(resultImage, new RectangleF(PointF.Empty, image.Size)), 1, UIImageOrientation.Up);
                return(finalImage);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(image);
            }
        }
Exemplo n.º 3
0
        public static UIImage Blur(this UIImage image, float radius)
        {
            if (image == null)
            {
                return(null);
            }
            try
            {
                var imageToBlur = CIImage.FromCGImage(image.CGImage);

                if (imageToBlur == null)
                {
                    return(image);
                }
                var transform = new CIAffineClamp
                {
                    Transform = CGAffineTransform.MakeIdentity(),
                    Image     = imageToBlur
                };


                var gaussianBlurFilter = new CIGaussianBlur
                {
                    Image  = transform.OutputImage,
                    Radius = radius
                };

                if (context == null)
                {
                    context = CIContext.FromOptions(null);
                }

                var resultImage = gaussianBlurFilter.OutputImage;

                var finalImage = UIImage.FromImage(context.CreateCGImage(resultImage, new CGRect(CGPoint.Empty, image.Size)), 1,
                                                   UIImageOrientation.Up);
                return(finalImage);
            }
            catch (Exception ex)
            {
                LogManager.Shared.Report(ex);
                return(image);
            }
        }
Exemplo n.º 4
0
		CIImage AffineClamp ()
		{
			var affine_clamp = new CIAffineClamp () {
				Image = flower
			};

			return Crop (affine_clamp);
		}