2011-04-11 4 views
0

미리 감사드립니다. 이미지 뷰를 오버레이 뷰로 카메라에 추가하고 (카메라 뷰 및 이미지 뷰)를 단일 이미지로 저장하려고합니다. 나는 그것을 검색하고 stackoverflow 주어진 예제를 시도했지만 아무것도 빈 화면보다 표시되지 않습니다. 아무도 나를 도와주세요.카메라보기에 오버레이보기를 추가하고 저장하는 방법

+0

그냥 지금 개까지 카메라 옵션을 사용하지 않은 7kv7 @ 당신에게 – visakh7

답변

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]; 

} 

희망이 유를 받았습니다 감사 내가 그것을 시도 할 것이다

+0

도움이 대답에 해당하는 눈금을 클릭하여 몇 가지 답변을 받아 들일 수 있습니다 ur 응답을 위해. –

+0

UIImagePickerController를 사용해 볼 수 있습니다. 그것은 훨씬 쉬울 것입니다 – visakh7

+0

예. 나는 그것을 사용하고 있습니다. –

관련 문제