Don kris np
Don kris np

Reputation: 37

How to pixelate an image in iOS?

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.

Upvotes: 1

Views: 2244

Answers (3)

sreekanthk
sreekanthk

Reputation: 362

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

Upvotes: -1

Caleb
Caleb

Reputation: 124997

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.

Upvotes: 5

Andrea
Andrea

Reputation: 26385

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];

Upvotes: 5

Related Questions