开源美颜滤镜SDK代码解析

经过互联网和科技的不断普及,人们的生活已经发生了翻天覆地的变化,几乎所有的行业都与互联网有所接轨,工作和生活也走向了科技化的道路。在大家日常生活中有许多显而易见的改变,各种新兴的娱乐方式也是充斥在互联网和生活之中,短视频直播平台就是个典型的例子。短视频平台之所以爆火是因为抓住了时代和人们的需求,这其中还有一定的科学依据,相关研究表明,人类在相同的单位时间内受到刺激程度会因为媒介产生变化,例如视频刺激会大于声音、图片、文字带来的刺激,短视频平台中五花八门的内容满足了人们的所有刺激需求,因此才会爆火,再就是短视频中的美颜滤镜SDK更是让人“流连忘返”,用过一次就再也忘不掉。
开源美颜滤镜SDK代码解析_第1张图片
滤镜SDK接入短视频平台后展现出的效果非同凡响,它依靠图像增强技术,打造出多种不同风格的滤镜提供用户使用,例如:浪漫、清新、唯美、粉嫩等效果,用户可以使用多元化的滤镜实现不同风格的转变。很多用户经常向小编问起一个问题,“美颜滤镜SDK的代码是什么?”今天小编特意开一篇文章为大家解答一下。

  • (void)configureUI {

    NSArray arr = @[@“美颜”,@“美型”/,@“滤镜”*/];
    if (_segmentControl) {
    return;
    }
    _segmentControl = [[WNSegmentControl alloc] initWithTitles:arr];
    CGFloat bottom = _slider.frame.origin.y + _slider.frame.size.height;
    _segmentControl.frame = CGRectMake(0, bottom+20, window_width, MHStickerSectionHeight);
    ///修改MHUI
    _segmentControl.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:MHBlackAlpha];
    [_segmentControl setTextAttributes:@{NSFontAttributeName: Font_12, NSForegroundColorAttributeName: FontColorBlackNormal}
    forState:UIControlStateNormal];
    [_segmentControl setTextAttributes:@{NSFontAttributeName: Font_12, NSForegroundColorAttributeName: FontColorSelected}
    forState:UIControlStateSelected];
    _segmentControl.selectedSegmentIndex = 0;
    _segmentControl.widthStyle = WNSegmentedControlWidthStyleFixed;
    [_segmentControl addTarget:self action:@selector(switchList:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:_segmentControl];
    [self addSubview:self.lineView];
    [self addSubview:self.beautyView];
    self.lastView = self.beautyView;
    ///修改MHUI
    [self addSubview:self.bottomView];
    self.slider.maximumValue = 9;
    NSInteger currentIndex = [self.beautyView currentIndex];
    if(currentIndex == 0 || currentIndex == -1){
    self.slider.hidden = YES;
    }

    [self.faceView configureFaceData];
    NSString *type = [[NSUserDefaults standardUserDefaults] objectForKey: @“MHSDKVersion”];
    _viewsArray = @[self.beautyView,self.faceView,self.filtersView];
    }

  • (void)configureSlider{
    // self.slider.maximumValue = 9;
    }
    #pragma mark - Action

  • (void)switchList:(WNSegmentControl *)segment {
    UIView *view = [self.viewsArray objectAtIndex:segment.selectedSegmentIndex];
    self.slider.hidden = [view isEqual:self.filtersView];
    self.assembleType = segment.selectedSegmentIndex;
    if ([view isEqual:self.beautyView]) {
    NSInteger current = [self.beautyView currentIndex];
    if (current == 0 || current == -1){
    self.slider.hidden = YES;
    }else{
    self.slider.hidden = NO;
    }
    NSString *faceKey = [NSString stringWithFormat:@“beauty_%ld”,(long)self.beautyType];
    NSInteger currentValue = [[NSUserDefaults standardUserDefaults] integerForKey:faceKey];
    [self.slider setValue:currentValue animated:YES];
    self.slider.maximumValue = 9;
    } else {
    self.slider.maximumValue = 100;
    }
    if ([view isEqual:self.faceView]) {
    NSInteger current = [self.faceView currentIndex];
    if (current == 0 || current == -1){
    self.slider.hidden = YES;
    }else{
    self.slider.hidden = NO;
    }
    [self.faceView configureFaceData];
    NSString *faceKey = [NSString stringWithFormat:@“face_%ld”,(long)self.faceType];
    NSInteger currentValue = [[NSUserDefaults standardUserDefaults] integerForKey:faceKey];
    [self.slider setValue:currentValue animated:YES];
    }

    if (![view isEqual:self.lastView]) {
    [self.lastView removeFromSuperview];
    }
    [self addSubview:view];
    self.lastView = view;
    ///修改MHUI
    [self bringSubviewToFront:self.bottomView];
    }
    开源美颜滤镜SDK代码解析_第2张图片

//slider 滑动修改对应的效果

  • (void)handleBeautyAssembleEffectWithValue:(NSInteger)value {
    switch (self.assembleType) {
    case 0:{
    if (self.isTXSDK) {
    [self handleBeautyEffectsOfTXWithSliderValue:value];
    } else {
    [self handleBeautyEffectsWithSliderValue:value];
    }
    }

          break;
      case 1:
          [self handleFaceEffectsWithSliderValue:value];
          
          break;
      case 2:
          [self handleQuickBeautyWithSliderValue:value];
          break;
      default:
          break;
    

    }
    }
    #pragma mark - 底部按钮响应

  • (void)cameraAction:(BOOL)isTakePhoto{
    NSLog(@“点击了拍照”);
    if (isTakePhoto) {
    if ([self.delegate respondsToSelector:@selector(takePhoto)]) {
    [self.delegate takePhoto];
    }
    }else{
    if ([self.delegate respondsToSelector:@selector(clickPackUp)]) {
    [self.delegate clickPackUp];
    }
    }

以上就是小编为大家整理的开源美颜滤镜SDK的部分代码,受限于篇幅问题暂时只讲这些,如果您对美颜技术感兴趣,请关注我!后续我会更新更多美颜技术相关话题。

你可能感兴趣的:(美颜算法,开源,ios,objective-c,图像处理,1024程序员节)