2017-06-06 68 views
0

我想在相機預覽視圖圖層上添加一個png圖像(藍色矩形)。我從這個功能得到的預覽圖像:IOS如何合併相機預覽圖層上的一個圖像?

-(void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 
{ 
    UIImage * image1 = [self ImageFromSampleBuffer:sampleBuffer]; 
    NSData *imageData1; 
} 

而這個功能是設置預覽圖像到UIImageview。

-(void) SetPreview 
{ 


    session =[[AVCaptureSession alloc]init]; 
    session.sessionPreset = AVCaptureSessionPresetPhoto; 

    //Add device; 
    AVCaptureDevice*device = nil; 
    device = [self cameraWithPosition:AVCaptureDevicePositionFront]; 

    AVCaptureDeviceInput*input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil]; 

    if(!input) 
    { 
     NSLog(@"NO Input"); 
    } 

    [session addInput:input]; 

    //Output 

    output = [[AVCaptureVideoDataOutput alloc] init]; 
    [session addOutput:output]; 
    output.videoSettings = @{(NSString*)kCVPixelBufferPixelFormatTypeKey:@(kCVPixelFormatType_32BGRA)}; 

    //Preview layer 
    AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; 

    cameraView = self.view; 

    previewLayer.frame =CGRectMake(cameraView.bounds.origin.x+5, cameraView.bounds.origin.y+5, cameraView.bounds.size.width - 10, cameraView.bounds.size.height-10); 

    previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 


    [_vImage.layer addSublayer:previewLayer]; 
    timer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(snapshot) userInfo:nil repeats:YES]; 

    [session startRunning]; 


} 

我該如何實現此功能?

enter image description here

回答

0

enter image description here

我解決了這個問題,把 「回到圖」 上的視圖。