Posted By

satie83 on 05/17/12


Tagged

cocoa


Versions (?)

Image resize with CI


 / Published in: Objective C
 

URL: http://goo.gl/dBxSF

Core Image provides a lot of filter to apply to images. Here there is a snippet to modify the size of the image using the Lanczos algorithm. You have to give the image URL and the ratio of the scale. If the ratio is smaller than 1 it reduce, otherwise it enlarges the image.

  1. // Resize the image
  2. CIImage *ciImage = [CIImage imageWithContentsOfURL:<#ImageURL#>];
  3. CIFilter *scaleFilter = [CIFilter filterWithName:@"CILanczosScaleTransform"];
  4. [scaleFilter setValue:ciImage forKey:@"inputImage"];
  5. [scaleFilter setValue:[NSNumber numberWithFloat:<#ratio#>] forKey:@"inputScale"];
  6. [scaleFilter setValue:[NSNumber numberWithFloat:1.0] forKey:@"inputAspectRatio"];
  7. CIImage *finalImage = [scaleFilter valueForKey:@"outputImage"];

Report this snippet  

You need to login to post a comment.