UIGraphicsBeginImageContext with parameters

后端 未结 5 1413
忘了有多久
忘了有多久 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:26

    If you're using a newer retina display device, your code should factor in the resolution by using UIGraphicsBeginImageContextWithOptions instead of UIGraphicsBeginImageContext:

    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,YES,2.0);
    CGContextRef c = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(c, 0, -40);    // <-- shift everything up by 40px when drawing.
    [self.view.layer renderInContext:c];
    UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    This will render the retina display image context.

提交回复
热议问题