2011-07-07 7 views
2

私はUIKitとカメラ要素の両方を含む私のアプリケーションのスクリーンショットを撮りたい、実際に私のアプリケーションはIphoneのインテリアデコレーションアプリケーションです。ですから、私たちはカメラで家具を装飾することで、UIKitとCamera要素の両方を含むスクリーンショットを取ります。UIKitとカメラの両方を含む私のアプリのスクリーンショット

+0

が重複する可能性が気軽にできませんでしたhttp://stackoverflow.com/questions/2200736/how-to-take- a-screenshot-programmatically) –

答えて

0
// Delegate Function of UIImagePicker 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 

    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; 

    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. 
    [cameraOverlayVCObject cameraOverlayVCObject.view inContext:context]; 

    // Retrieve the screenshot image containing both the camera content and the overlay view 
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 

    // here is that final Image I am storing into Saved Photo Albums/ Library 
    UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil); 
    UIGraphicsEndImageContext(); 

    // I dont want my Camera to be Closed 
    //[self dismissModalViewControllerAnimated:YES]; 
    self.view.hidden = NO; 
} 

// now got Picture from Camera need to Render Context on it here is Function 
- (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); 
    [appDelegate.cameraPicker dismissModalViewControllerAnimated:YES]; 
} 

何も理解しやすい、([プログラムでスクリーンショットを撮る方法】の

-1

使用これは、

UIGraphicsBeginImageContext(webview.frame.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 

これは、あなたのアプリのスクリーンショットをキャプチャすることができますし、それはあなたのiPhoneで写真に保存されます。

+0

私はこれらすべての解決策を完了しました。これは、カメラ要素ではなく画像としてキャプチャされます。私はそれらを両方同時に捕獲したい。 UIImagesやButton CameraView + CameraViewに追加しました。(カメラで見ていることを意味します)AV Foundationで行われると思いますが、誰かが助けてくれれば分かりません。このチュートリアルhttp://developer.apple.com/library/ios/#qa/qa1714/_index.htmlを参照していますが、デリゲート関数は呼び出されません。なにか提案を? –

関連する問題