所用到的知识点为 颜色矩阵,android里面的概念,可以先了解下
//lomo
const float colormatrix_lomo[] = {
1.7f, 0.1f, 0.1f, 0, -73.1f,
0, 1.7f, 0.1f, 0, -73.1f,
0, 0.1f, 1.6f, 0, -73.1f,
0, 0, 0, 1.0f, 0 };
//黑白
const float colormatrix_heibai[] = {
0.8f, 1.6f, 0.2f, 0, -163.9f,
0.8f, 1.6f, 0.2f, 0, -163.9f,
0.8f, 1.6f, 0.2f, 0, -163.9f,
0, 0, 0, 1.0f, 0 };
//旧化
const float colormatrix_huajiu[] = {
0.2f,0.5f, 0.1f, 0, 40.8f,
0.2f, 0.5f, 0.1f, 0, 40.8f,
0.2f,0.5f, 0.1f, 0, 40.8f,
0, 0, 0, 1, 0 };
GPUImage 为图片添加滤镜
//中间突出 四周暗,可更换为其他的滤镜
GPUImageVignetteFilter *passthroughFilter = [[GPUImageVignetteFilter alloc]init];
[passthroughFilter useNextFrameForImageCapture];
//获取数据源
GPUImagePicture *stillImageSource=[[GPUImagePicture alloc]initWithImage:image];
[stillImageSource addTarget:passthroughFilter];
//开始渲染
[stillImageSource processImage];
UIImage *finallImage = [passthroughFilter imageFromCurrentFramebuffer];
UIImageWriteToSavedPhotosAlbum(finallImage, nil, nil, nil);
https://github.com/chjwrr/imageAddFilter