Ich beginne gerade in Objective-C und ich versuche, eine einfache App zu erstellen, wo es die Kameraansicht mit einem Unschärfe-Effekt zeigt. Ich habe die Kamera-Ausgabe mit dem AVFoundation-Framework arbeiten lassen. Jetzt versuche ich, das Core-Bild-Framework zu verbinden, aber ohne zu wissen, wie das geht, Apple-Dokumentation ist verwirrend für mich und die Suche nach Anleitungen und Tutorials führt online zu keinen Ergebnissen. Vielen Dank im Voraus für die Hilfe.Wie wird ein CIFilter in eine Kameraansicht ausgegeben?
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController()
@property (strong ,nonatomic) CIContext *context;
@end
@implementation ViewController
AVCaptureSession *session;
AVCaptureStillImageOutput *stillImageOutput;
-(CIContext *)context
{
if(!_context)
{
_context = [CIContext contextWithOptions:nil];
}
return _context;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)viewWillAppear:(BOOL)animated{
session = [[AVCaptureSession alloc] init];
[session setSessionPreset:AVCaptureSessionPresetPhoto];
AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error;
AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error];
if ([session canAddInput:deviceInput]) {
[session addInput:deviceInput];
}
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
CALayer *rootLayer = [[self view] layer];
[rootLayer setMasksToBounds:YES];
CGRect frame = self.imageView.frame;
[previewLayer setFrame:frame];
[previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
[rootLayer insertSublayer:previewLayer atIndex:0];
stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil];
[stillImageOutput setOutputSettings:outputSettings];
[session addOutput:stillImageOutput];
[session startRunning];
}
@end
Wow. Okay! werde das hier testen. Vielen Dank! –
Wie mache ich das für die Aufnahme des gleichen Videos? –