How to take screenshot for the entire screen no matter which app is at front most in iOS 7(Jailbroken)

后端 未结 4 808
逝去的感伤
逝去的感伤 2021-02-01 23:55

Before iOS7 I use UIGetScreenImage() function to take the screenshot easily, but in iOS7, it becomes deprecated, now are there any good methods to archive this?Than

4条回答
  •  长情又很酷
    2021-02-02 00:44

    Alternative way to replace UIGetScreenImage()

    CGImageRef screen = UIGetScreenImage();
    

    The above code is one line of code to capture the screen, but Apple does not open the above API UIGetScreenImage() for the public app. i.e. fail to upload to Apple for approval. So the alternative way to capture screen and save it are listed as below.

    - (void)captureAndSaveImage
    {    
    
        // Capture screen here... and cut the appropriate size for saving and uploading
        UIGraphicsBeginImageContext(self.view.bounds.size);
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        // crop the area you want 
        CGRect rect;
        rect = CGRectMake(0, 10, 300, 300);    // whatever you want
        CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
        UIImage *img = [UIImage imageWithCGImage:imageRef]; 
        CGImageRelease(imageRef);
        UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
        imageView.image = img; // show cropped image on the ImageView     
    }
    
    // this is option to alert the image saving status
    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
    {
        UIAlertView *alert;
    
        // Unable to save the image  
        if (error)
            alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                               message:@"Unable to save image to Photo Album." 
                                              delegate:self cancelButtonTitle:@"Dismiss" 
                                     otherButtonTitles:nil];
        else // All is well
            alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                               message:@"Image saved to Photo Album." 
                                              delegate:self cancelButtonTitle:@"Ok" 
                                     otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    

    some of link help you how-to-legally-replace-uigetscreenimage

提交回复
热议问题