iOS image處理BlendModes

ZY_FlyWay發表於2018-08-30
 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;  
        }  

相關文章