iOS image处理BlendModes

2022-05-06 17:04:02 浏览数 (1)

代码语言:javascript复制
 switch (blendMode) {  
        case kCGBlendModeNormal: {  
            strMsg = @"kCGBlendModeNormal: 正常;也是默认的模式。前景图会覆盖背景图";  
            break;  
        }  
        case kCGBlendModeMultiply: {  
            strMsg = @"kCGBlendModeMultiply: 正片叠底;混合了前景和背景的颜色,最终颜色比原先的都暗";  
            break;  
        }  
        case kCGBlendModeScreen: {  
            strMsg = @"kCGBlendModeScreen: 滤色;把前景和背景图的颜色先反过来,然后混合";  
            break;  
        }  
        case kCGBlendModeOverlay: {  
            strMsg = @"kCGBlendModeOverlay: 覆盖;能保留灰度信息,结合kCGBlendModeSaturation能保留透明度信息,在imageWithBlendMode方法中两次执行drawInRect方法实现我们基本需求";  
            break;  
        }  
        case kCGBlendModeDarken: {  
            strMsg = @"kCGBlendModeDarken: 变暗";   //将线条色变为黑色,背景色设置为目的色
            break;  
        }  
        case kCGBlendModeLighten: {  
            strMsg = @"kCGBlendModeLighten: 变亮";  
            break;  
        }  
        case kCGBlendModeColorDodge: {  
            strMsg = @"kCGBlendModeColorDodge: 颜色变淡";  
            break;  
        }  
        case kCGBlendModeColorBurn: {  
            strMsg = @"kCGBlendModeColorBurn: 颜色加深";  //线条颜色(原本)加深,背景色设置为目的色
            break;  
        }  
        case kCGBlendModeSoftLight: {  
            strMsg = @"kCGBlendModeSoftLight: 柔光";  
            break;  
        }  
        case kCGBlendModeHardLight: {  
            strMsg = @"kCGBlendModeHardLight: 强光";  //全为目的色
            break;  
        }  
        case kCGBlendModeDifference: {  
            strMsg = @"kCGBlendModeDifference: 插值";  
            break;  
        }  
        case kCGBlendModeExclusion: {  
            strMsg = @"kCGBlendModeExclusion: 排除";  
            break;  
        }  
        case kCGBlendModeHue: {  
            strMsg = @"kCGBlendModeHue: 色调";  
            break;  
        }  
        case kCGBlendModeSaturation: {  
            strMsg = @"kCGBlendModeSaturation: 饱和度";  
            break;  
        }  
        case kCGBlendModeColor: {  
            strMsg = @"kCGBlendModeColor: 颜色";   //感觉将图片线条色设置为白色,背景色设置为目的色,之后再再图片上加一个有透明度的目的色
            break;  
        }  
        case kCGBlendModeLuminosity: {  
            strMsg = @"kCGBlendModeLuminosity: 亮度";  
            break;  
        }  
            //Apple额外定义的枚举  
            //R: premultiplied result, 表示混合结果  
            //S: Source, 表示源颜色(Sa对应透明度值: 0.0-1.0)  
            //D: destination colors with alpha, 表示带透明度的目标颜色(Da对应透明度值: 0.0-1.0)  
        case kCGBlendModeClear: {  
            strMsg = @"kCGBlendModeClear: R = 0"; //1.清空(如果图标背景色为白色则为全白) 
            break;  
        }  
        case kCGBlendModeCopy: {  
            strMsg = @"kCGBlendModeCopy: R = S";  //2全色覆盖整个图片
            break;  
        }  
        case kCGBlendModeSourceIn: {  
            strMsg = @"kCGBlendModeSourceIn: R = S*Da";  //3.线条变色
            break;  
        }  
        case kCGBlendModeSourceOut: {  
            strMsg = @"kCGBlendModeSourceOut: R = S*(1 - Da)";  //4.背景变为目的色,线条自动变为白色(比如图标线条原为蓝色,会自动变为白色)
            break;  
        }  
        case kCGBlendModeSourceAtop: {  
            strMsg = @"kCGBlendModeSourceAtop: R = S*Da   D*(1 - Sa)";   //5.线条变色,目前感觉和SourceIn效果一致
            break;  
        }  
        case kCGBlendModeDestinationOver: {  
            strMsg = @"kCGBlendModeDestinationOver: R = S*(1 - Da)   D";  //6.背景色变为目的色,线条色不变
            break;  
        }  
        case kCGBlendModeDestinationIn: {  
            strMsg = @"kCGBlendModeDestinationIn: R = D*Sa;能保留透明度信息";  //7.只看到线条色(本色),无其他颜色
            break;  
        }  
        case kCGBlendModeDestinationOut: {  
            strMsg = @"kCGBlendModeDestinationOut: R = D*(1 - Sa)";     //8.空白什么都没哟
            break;  
        }  
        case kCGBlendModeDestinationAtop: {  
            strMsg = @"kCGBlendModeDestinationAtop: R = S*(1 - Da)   D*Sa";  //9.会把整个矩形的背景填充目的色(如图9系列)原色保留
            break;  
        }  
        case kCGBlendModeXOR: {  
            strMsg = @"kCGBlendModeXOR: R = S*(1 - Da)   D*(1 - Sa)";  //10.线条变白,背景色变为目的色
            break;  
        }  
        case kCGBlendModePlusDarker: {  
            strMsg = @"kCGBlendModePlusDarker: R = MAX(0, (1 - D)   (1 - S))";  //11.线条变为黑色, 背景色变为目的色
            break;  
        }  
        case kCGBlendModePlusLighter: {  
            strMsg = @"kCGBlendModePlusLighter: R = MIN(1, S   D)(最后一种混合模式)";  //12.线条变为白色(混合色:如color为红色,就是偏粉色的白,有一定透明度的感觉)
            break;  
        }  
        default: {  
            break;  
        }  

0 人点赞