CIEdges 濾鏡的使用

CIEdges 濾鏡效果如下

濾鏡效果

先看參數(shù):

CIFilter *filter = [CIFilter filterWithName:@"CIEdges"];
NSLog(@"%@ - %@", filterName, filter.attributes);
    inputImage =     {
        CIAttributeClass = CIImage;
        CIAttributeDescription = "The image to use as an input image. For filters that also use a background image, this is the foreground image.";
        CIAttributeDisplayName = Image;
        CIAttributeType = CIAttributeTypeImage;
    };
    inputIntensity =     {
        CIAttributeClass = NSNumber;
        CIAttributeDefault = 1;
        CIAttributeDescription = "The intensity of the edges. The larger the value, the higher the intensity.";
        CIAttributeDisplayName = Intensity;
        CIAttributeIdentity = 0;
        CIAttributeMin = 0;
        CIAttributeSliderMax = 10;
        CIAttributeSliderMin = 0;
        CIAttributeType = CIAttributeTypeScalar;
    };

所以這個濾鏡除了image以外還需要以下參數(shù):

  • inputIntensity:強度,默認(rèn)值1,范圍0~10

實例

代碼

    CIFilter *filter = [CIFilter filterWithName:@"CIEdges"];
    CIContext *context = [CIContext contextWithOptions:nil];
    NSLog(@"%@ - %@", filterName, filter.attributes);
    if (filter.attributes[kCIInputImageKey]) {
        [filter setValue:inputImage forKey:kCIInputImageKey];
        
        if (filter.attributes[kCIInputIntensityKey]) {
            [filter setValue:@(3) forKey:kCIInputIntensityKey];
        }


        CIImage *outPutImage = filter.outputImage;
        CGImageRef imageRef = [context createCGImage:outPutImage fromRect:outPutImage.extent];
        if (imageRef) {
            return [UIImage imageWithCGImage:imageRef];
        }
    }
    
    return nil;

效果

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容