1

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.

Justin
  • 6,611
  • 3
  • 36
  • 57
  • i think u can use UIImageJPEGRepresentation(image, compressibility) the lower the compression the higher the quality. so my suggestion is take 4 UIImages and by reducing the compressibility from 1 to 0.2 and store them. When user 1st tap show the image with 0.2 compressibility, when he taps again show the image with 0.4 compressibility by reducing the quality and so on. if u want reverse the method – sreekanthk Sep 04 '14 at 13:29
  • hi, do you have any example code or links for that? – Don kris np Sep 04 '14 at 13:31
  • ok let me try thanks – Don kris np Sep 04 '14 at 13:38
  • 1
    possible duplicate of [How to pixelate an UIImage?](http://stackoverflow.com/questions/10470294/how-to-pixelate-an-uiimage) – n00bProgrammer Sep 04 '14 at 13:46
  • @sreekanthk can u once again post your answer – Don kris np Sep 04 '14 at 14:43
  • why? @Donkrisnp i dont want to down my rep. – sreekanthk Sep 05 '14 at 06:34

3 Answers3

5

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];
Andrea
  • 26,120
  • 10
  • 85
  • 131
  • i have done this but i got some errors please check this link for screenshots http://postimg.org/image/6vq9ovyu5/7d68104f/ – Don kris np Sep 04 '14 at 14:25
  • You must follow the instruction on the githubpage to import the framework – Andrea Sep 04 '14 at 14:27
  • can u create a sample example please.. i have tried and it showing me errors – Don kris np Sep 04 '14 at 14:43
  • You have to use GPUImagePicture not UIImage. See here: GPUImagePicture *mainCurrentImg = [[GPUImagePicture alloc] initWithImage: inputImage]; – Rahul Dadhich May 05 '15 at 12:24
  • is this possible to work pixelation with PanGesture on image...? mean to say particular pixels.. – Salman Ghumsani Dec 04 '16 at 18:04
  • Not in an easy way, at the moment it does on a full image, but you can draw an area with a pan gesture, copy the image in that area and apply the filter to them – Andrea Dec 04 '16 at 18:57
5

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.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • This is pretty slick. I'm amazed (and embarrassed) I have not heard of this before. – n00bProgrammer Sep 04 '14 at 13:50
  • i didnt see any pixelation in that doc sorry – Don kris np Sep 04 '14 at 14:00
  • @Donkrisnp The example in listing 1-1 on the linked page shows filtering using `CISepiaTone`, but that's just to illustrate the process. You can easily modify the code to use a different filter (like `CIPixellate`) and setting values for whatever keys are appropriate according to the docs for your chosen filter. – Caleb Sep 04 '14 at 14:06
  • @n00bProgrammer Core Image is *very* slick. Brad Larson's GPUImage is even more slick in some ways (faster, simpler), but it's something else that you have to add to your project. Either one would likely be fine for the OP's purpose. – Caleb Sep 04 '14 at 14:09
-1

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

sreekanthk
  • 362
  • 2
  • 21