iOS 贴纸+滤镜功能实现

引入三个文件
重新绘制
#import "ImageUtil.h"
滤镜色值
#import "ColorMatrix.h"
图片裁剪
#import "UIImage+AddFunction.h"

ImageUtil内存释放问题稍作修改
void * bitmap; 定义一下
free(bitmap);   之后释放
/**
 *  滤镜 返回需要图片
 */
- (UIImage *)buttonSetImageWithButton:(UIButton *)button
{
    NSInteger currentIndex = button.tag - 1000;
    UIImage *buttonImage;
    switch (currentIndex)
    {
        case 0:
        {
            buttonImage = self.originImage;
        }
            break;
        case 1:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_lomo];
        }
            break;
        case 2:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_heibai];
        }
            break;
        case 3:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_huajiu];
        }
            break;
        case 4:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_gete];
        }
            break;
        case 5:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_ruise];
        }
            break;
        case 6:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_danya];
        }
            break;
        case 7:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_jiuhong];
        }
            break;
        case 8:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_qingning];
        }
            break;
        case 9:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_langman];
        }
            break;
        case 10:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_guangyun];
        }
            break;
        case 11:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_landiao];
        }
            break;
        case 12:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_menghuan];
        }
            break;
        case 13:
        {
            buttonImage = [ImageUtil imageWithImage:self.originImage withColorMatrix:colormatrix_yese];
        }
            break;
            
        default:
            break;
    }

    return buttonImage;
}
引入头文件 一个滤镜一个贴纸
#import "PPXFilterScrollView.h"
#import "PPXStickersScrollView.h"
//代理方法
- (void)filterImage:(UIImage *)editedImage
{
    _stageView.originImage = editedImage;
}

- (void)stickersImage:(UIImage *)editedImage
{
    //在这里 添加 贴纸
    [_stageView addPasterWithImg:editedImage] ;
}
完成调用
UIImage *imgResult = [_stageView doneEdit] ;
git下载地址
https://github.com/W-King/PPX_FilterAndStickers.git

你可能感兴趣的:(iOS 贴纸+滤镜功能实现)