參考資料:
https://juejin.im/post/5d1860a2f265da1bb27746d6
并再此基礎(chǔ)上添加了其他濾鏡:二分、四分、九分、灰度、暖色、冷色、漩渦、矩形馬賽克、六邊形馬賽克、三角形馬賽克、圓形馬賽克、縮放、閃白、抖動(dòng)、靈魂出竅、毛刺、幻覺(jué)、浮雕。
效果圖:
IMG_0800.PNG
也能夠在紋理中獲取處理后的UIImage
// 獲取紋理對(duì)應(yīng)的 UIImage,調(diào)用前先綁定對(duì)應(yīng)的幀緩存
- (UIImage *)imageFromTextureWithWidth:(int)width height:(int)height {
int size = width * height * 4;
GLubyte *buffer = malloc(size);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, size, NULL);
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * width;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// 此時(shí)的 imageRef 是上下顛倒的,調(diào)用 CG 的方法重新繪制一遍,剛好翻轉(zhuǎn)過(guò)來(lái)
UIGraphicsBeginImageContext(CGSizeMake(width, height));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
free(buffer);
self.imageView.image = image;
return image;
}