How to pixelate an image in iOS?

2.2k Views Asked by At

I'm to create a simple app with the following features:

  1. First page of app will display a list of images from server (when we display these images we should pixelate it).

  2. Once user clicks on any pixelated image then it will open in detail view (opens that pixelated image in a new ViewController).

When the user does a single touch on the detail view controller image, then it will reduce its pixelation level, and after some clicks the user can see the real image.

My problem is I am not able to find out a way to pixelate all these things dynamically. Please help me.

3

There are 3 best solutions below

6
On BEST ANSWER

The GPUImage Framework has a pixellate filter, since it uses the GPUAcceleration applying the filter on an image is very fast and you can vary the pixellate level at runtime.

UIImage *inputImage = [UIImage imageNamed:<#yourimageame#>];
GPUImagePixellateFilter *filter = [[GPUImagePixellateFilter alloc] init];
UIImage *filteredImage = [filter imageByFilteringImage:inputImage];
2
On

UIImage *yourImage = [UIImage imageNamed:@"yourimage"]; NSData *imageData1 = UIImageJPEGRepresentation(yourImage, 0.2); NSData *imageData2 = UIImageJPEGRepresentation(yourImage, 0.3);

and so on upto

NSData *imageDataN = UIImageJPEGRepresentation(yourImage, 1);

show the imageData with the help of the below:

UIImage *compressedImage = [UIImage imageWithData:imageData1];

try this. Happy coding

4
On

An easy way to pixellate an image would be to use the CIPixellate filter from Core Image.

Instructions and sample code for processing images with Core Image filters can be found in the Core Image Programming Guide.