使用GPUImage实现加水印效果

//摄像机初始化

    stillCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1920x1080 cameraPosition:AVCaptureDevicePositionBack];

//  方向

    stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

//    视频保存路径

    pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie2.mp4"];

    unlink([pathToMovie UTF8String]);

  //    NSLog(@"视频路径%@",pathToMovie);

    NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];

//    录制器初始化

    movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1080, 1960)];

    movieWriter.encodingLiveVideo = YES;

//    视频预览页面

    GPUImageView *filterView = [[GPUImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

    [filterView setBackgroundColorRed:1 green:1 blue:1 alpha:1];

    [self.view addSubview:filterView];


添加滤镜

//水印页面

UIImage *image = [self imageAddLocalImage:[UIImage imageNamed:@"transparent.png"] addMsakImage:[UIImage imageNamed:@"course.png"]];

        self.pptPicture = [[GPUImagePicture alloc] initWithImage:image smoothlyScaleOutput:YES];

//        [self.sourcePicture processImage];

    self.alphaBlendFilter = [[GPUImageAlphaBlendFilter alloc] init];

    //mix即为叠加后的透明度,这里就直接写1.0了

    self.alphaBlendFilter.mix = 1;

    [self.alphaBlendFilter addTarget:filterView];

    [stillCamera addTarget:self.alphaBlendFilter];

    [self.pptPicture addTarget:self.alphaBlendFilter];

    [self.alphaBlendFilter  addTarget:movieWriter];


[stillCamera startCameraCapture];//开始拍摄

效果


你可能感兴趣的:(使用GPUImage实现加水印效果)