Screenshot with video overlay?

Discussion in 'iOS Programming' started by xArtx, Jul 21, 2012.

  1. xArtx macrumors 6502a

    Mar 30, 2012
    Hello there :)

    I am using this code to overlay a custom size video preview window to a
    Quartz2D screen:

        [self setCaptureManager:[[CaptureSessionManager alloc] init]];
    	[[self captureManager] addVideoInput];
    	[[self captureManager] addVideoPreviewLayer];
    	//CGRect layerRect = [[[self view] layer] bounds];
        CGRect layerRect = CGRectMake(0,360,320,120);    
    	[[[self captureManager] previewLayer] setBounds:layerRect];
    	[[[self captureManager] previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),
    	[[[self view] layer] addSublayer:[[self captureManager] previewLayer]];
    	[[captureManager captureSession] startRunning];
    and also this code, to capture screenshots:
              //  if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
              //  UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
              //  } else {
              //  UIGraphicsBeginImageContext(self.window.bounds.size);
              //  }
              //  [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
              //  UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
              //  UIGraphicsEndImageContext();
              //  UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);   
    Problem is, when the live camera feed is on the screen, but it is not present
    in the screenshots when I check them in the Camera Roll.
    I want the camera preview to be captured in the shots.
    Any ideas what I'm doing wrong?
    Cheers, Art.


    I'm a beginner, but it might be that the camera feed is happening in a different view or something. The camera code is in the view controller.m file,
    while the snapshot code is in the same file all the drawing is done "Draw2D.m".
  2. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia

    Under the covers, video is displayed to a video preview using a special type of CALAyer. Certain kinds of layers, like OpenGL layers, can't be captured with the usual
    renderInContext call. There must be a way to do it, since the system screen capture function (triggered by pressing the home button and power button at the same time) is able to, but I don't know how. Maybe somebody else knows the trick and can enlighten us?

Share This Page