單張圖片處理
1.單個(gè)濾鏡
//設(shè)置濾鏡
[self.filter useNextFrameForImageCapture];
[self.filter forceProcessingAtSizeRespectingAspectRatio:self.image.size];
self.filter.brightness = 0.5;
// 傳入要處理的圖片
GPUImagePicture *picture = [[GPUImagePicture alloc] initWithImage:self.image];
// 給圖片添加濾鏡
[picture addTarget:self.filter];
//渲染
[picture processImage];
//從濾鏡中獲取圖片
[self.imageView setImage:self.filter.imageFromCurrentFramebuffer];
2.濾鏡組
//第一個(gè)濾鏡
self.filter1 = [[GPUImageBrightnessFilter alloc] init];
self.filter1.brightness = 0.0;
//第二個(gè)濾鏡
self.filter2 = [[GPUImageSaturationFilter alloc] init];
self.filter2.saturation = 1.0;
//濾鏡組
self.groupFilter = [[GPUImageFilterGroup alloc] init];
[self.groupFilter addTarget:self.filter1];
[self.groupFilter addTarget:self.filter2];
[self.groupFilter forceProcessingAtSizeRespectingAspectRatio:self.image.size];
//濾鏡間的依賴關(guān)系有巧,一個(gè)濾鏡處理好后再去處理下一個(gè)濾鏡
[self.filter1 addTarget:self.filter2];
[self.groupFilter setInitialFilters:[NSArray arrayWithObject:self.filter1]];
[self.groupFilter setTerminalFilter:self.filter2];
//輸入源
GPUImagePicture *picture = [[GPUImagePicture alloc] initWithImage:self.image];
[picture addTarget:self.groupFilter];
//處理圖片并獲取輸出
[self.groupFilter useNextFrameForImageCapture];
[picture processImage];
[self.imageView setImage:self.groupFilter.imageFromCurrentFramebuffer];
3.美顏相機(jī)
//創(chuàng)建相機(jī)
self.Camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront];
self.Camera.outputImageOrientation = UIInterfaceOrientationPortrait;
//創(chuàng)建濾鏡
self.filter = [[GPUImageSaturationFilter alloc] init];
self.filter.saturation = 1.0;
//相機(jī)上添加濾鏡
[self.Camera addTarget:self.filter];
//圖片處理后的輸出展示
self.GPUImageView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
[self.view addSubview:self.GPUImageView];
//輸出結(jié)果要給顯示
[self.filter addTarget:self.GPUImageView];
//開始捕獲圖像
[self.Camera startCameraCapture];
//拍照獲取的圖片
[self.Camera capturePhotoAsJPEGProcessedUpToFilter:self.filter withCompletionHandler:^(NSData *processedJPEG, NSError *error) {
}];
4.視屏錄制
初始化設(shè)置
initWithMovieURL:size 視屏保存的地址和視頻的大小
startRecording 開始錄制
[filter addTarget:self.movieWriter] 添濾鏡
[self.movieWriter startRecording] 開始錄制
[self.videoCamera pauseCameraCapture]; 暫停
[self.videoCamera resumeCameraCapture]; 恢復(fù)