Resolution of capture screen image is not retina

一个人想着一个人 提交于 2019-12-24 10:59:42

问题


I am using the following code for capture a view on the screen but it is not as sharp as on the screen. the imageView size is 200x200point but the scale is 2.0 (with retina screen). The saved img size is 200x200 px. how could i make the img as sharp as the original one? Any help will be appreciated!
- (UIImage*)captureView:(UIView *)theView {

    CGRect rect = theView.frame;
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [theView.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

回答1:


You are using the old way of creating the image context. Use this instead:

UIGraphicsBeginImageContextWithOptions(rect.size, YES, [UIScreen mainScreen].scale);

The older UIGraphicsBeginImageContext function always assumes a scale of 1.0.

Replace 'YES' with 'NO' if you need the alpha channel.




回答2:


Try like that:

     CGRect screenRect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;


来源:https://stackoverflow.com/questions/13832871/resolution-of-capture-screen-image-is-not-retina

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!