ios how to capture a particular portion of screen

后端 未结 6 1898
一生所求
一生所求 2020-12-14 11:41

I want to capture a particular portion of iPhone screen. I used UIGraphicsBeginImageContextWithOptions, but couldn\'t capture a portion of screen with this. Ple

6条回答
  •  生来不讨喜
    2020-12-14 12:30

    Another method to capture clear screenshot;

    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
                UIGraphicsBeginImageContextWithOptions(self.captureView.frame.size, NO, [UIScreen mainScreen].scale);
            else
                UIGraphicsBeginImageContext(self.captureView.frame.size);
    
            [self.captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
            UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
            [viewImage drawInRect:CGRectMake(0.0, 0.0, 640,960)];
            //NSData*m_Imgdata=UIImagePNGRepresentation(viewImage);
            NSData*m_Imgdata=UIImageJPEGRepresentation(viewImage, 1.0);
    
           // UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
    
            UIGraphicsEndImageContext();
    

提交回复
热议问题