Image resize with CI


/ Published in: Objective C
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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"];

URL: http://goo.gl/dBxSF

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.