使用CoreImage教程
CoreImage包含有很多实用的滤镜,专业处理图片的库,为了能看到各种渲染效果,请使用如下图片素材.
现在可以开始教程了:
#define FIX_IMAGE(image) fixImageWidth(image, 320.f) // 固定图片的宽度 UIImage * fixImageWidth(UIImage *image, CGFloat width) { float newHeight = image.size.height * (width / image.size.width); CGSize size = CGSizeMake(width, newHeight); UIGraphicsBeginImageContextWithOptions(size, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(context, 0.0, size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextSetBlendMode(context, kCGBlendModeCopy); CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), image.CGImage); UIImage *imageOut = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return imageOut; }