简体   繁体   English

我的应用程序的屏幕截图,其中包含 UIKit 和相机

[英]screenshot of my app that contains both UIKit and Camera

I want to take Screen Shot of my Application containing both UIKit and Camera Elements, Actually my application is interior Decoration Application in Iphone.我想截取包含 UIKit 和相机元素的应用程序的屏幕截图,实际上我的应用程序是 Iphone 中的室内装饰应用程序。 So requirement is when we done with decorating furniture on camera we take screenshot, that contains both UIKit and Camera element.所以要求是当我们在相机上完成装饰家具时,我们会截取屏幕截图,其中包含 UIKit 和相机元素。

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

anything couldn't understandable, feel free to ask有什么不明白的,欢迎追问

use this,用这个,

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

This will allow you to capture a screenshot of your app and it will be saved in photos in your iPhone.这将允许您捕获应用程序的屏幕截图,并将其保存在 iPhone 中的照片中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM