0

Thanks in advance. I want to add an image view as a overlay view to the camera and save both the (cameraview and image view )as a single image. I searched for it and tried the example given in stackoverflow but it is not displaying any thing than blank screen .If any one know please help me.

Michaël
  • 6,676
  • 3
  • 36
  • 55
Sandy_ios
  • 669
  • 1
  • 11
  • 25
  • Just accept some answers by clicking on the tick mark corresponding to the answer which helped you – visakh7 Apr 11 '11 at 09:50

1 Answers1

1
- (void)renderView:(UIView*)view inContext:(CGContextRef)context
{
    // -renderInContext: renders in the coordinate space of the layer,
    // so we must first apply the layer's geometry to the graphics context
    CGContextSaveGState(context);
    // Center the context around the window's anchor point
    CGContextTranslateCTM(context, [view center].x, [view center].y);
    // Apply the window's transform about the anchor point
    CGContextConcatCTM(context, [view transform]);
    // Offset by the portion of the bounds left of and above the anchor point
    CGContextTranslateCTM(context,
                          -[view bounds].size.width * [[view layer] anchorPoint].x,
                          -[view bounds].size.height * [[view layer] anchorPoint].y);

    // Render the layer hierarchy to the current context
    [[view layer] renderInContext:context];

    // Restore the context
    CGContextRestoreGState(context);
}

// this get called when an image has been taken from the camera
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    //cameraImage = image;
    CGSize imageSize = [[UIScreen mainScreen] bounds].size;
    if (NULL != UIGraphicsBeginImageContextWithOptions)
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
    else
        UIGraphicsBeginImageContext(imageSize);

    CGContextRef context = UIGraphicsGetCurrentContext();


    // Draw the image returned by the camera sample buffer into the context. 
    // Draw it into the same sized rectangle as the view that is displayed on the screen.
    float menubarUIOffset = 44.0;
    UIGraphicsPushContext(context);
    [image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height-menubarUIOffset)];
    UIGraphicsPopContext();

    // Render the camera overlay view into the graphic context that we created above.
    [self renderView:self.imagePicker.view inContext:context];

    // Retrieve the screenshot image containing both the camera content and the overlay view
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);
    UIGraphicsEndImageContext();
    [self.imagePicker dismissModalViewControllerAnimated:YES];

}

Hope this helps

visakh7
  • 26,380
  • 8
  • 55
  • 69