Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to take screen shot of an iOS device

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 858
    Comment on it

    If you want to capture screen of an iOS device as you take the same from iPhone by pressing 'Power' button an 'Home' button then here is the code. It will take screen shot even if there is any transformation or transition running.

    First you have to write this function where only two lines are written. In the first line of code it take snapshot of that particular view which you will mention here. Where as in the second line of code, it takes that area's screen shot and save it to the photo gallery of the device.
     

    This method calls two methods.

    - (void)layoutSubviews{
        
        UIView *snapshot = [self snapshotViewAfterScreenUpdates:YES];
        UIImageWriteToSavedPhotosAlbum([self snapshot:snapshot], nil, nil, nil);
        
    }

    Inside this function you have to mention the name of the view which you wanna capture.

    - (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates{
        
        return self.view;
    }

    In this final function we are getting the graphic context of the view which we have passed in the above function.

    - (UIImage *)snapshot:(UIView *)view
    {
        UIGraphicsBeginImageContextWithOptions(backGroundView.frame.size, NO, 0.0);
    
        // Render our snapshot into the image context
        [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
    
        // Grab the image from the context
        UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    
        // Finish using the context
        UIGraphicsEndImageContext();
        
        return viewImage;
    }

    **Happy Coding !!!**

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: