UIGraphicsBeginImageContext with parameters

后端 未结 5 1350
忘了有多久
忘了有多久 2021-02-19 19:06

I am taking a screenshot in my application. I am able to take the screenshot.

Now I want to take the screenshot by specifying the x and y coordinate. Is that possible?

5条回答
  •  故里飘歌
    2021-02-19 19:18

    Just do something like this, way easier than all those complex calculations

    + (UIImage *)imageWithView:(UIView *)view {
        UIGraphicsBeginImageContextWithOptions([view bounds].size, NO, [[UIScreen mainScreen] scale]);
    
        [[view layer] renderInContext:UIGraphicsGetCurrentContext()];
    
        UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    
        UIGraphicsEndImageContext();
    
        return result;
    }
    

提交回复
热议问题