Problem about @2X

不想你离开。 提交于 2020-01-05 07:08:34

问题


1.I use below code for take screenshot.is it necessary to change it for high resolution

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

2.what does happen if i just use one image with 640*960 resolution for both low and high quality ? (means that don't use image with @2x)


回答1:


That will only take normal (320x480) resolution screenshots. So in answer to 1, yes. Older generation devices can do double resolution too, the screen just can't display it.

To take a screenshot at the res of the device you can do this:

CGSize size = self.view.bounds.size;
CGFloat scale = 1.0f;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    scale = [[UIScreen mainScreen] scale];
    size = CGSizeApplyAffineTransform(size, CGAffineTransformMakeScale(scale, scale));
}

UIGraphicsBeginImageContext(size);

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM(context, scale, scale);

[self.view.layer renderInContext:context]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

Taking double res on older devices does work, and will be scaled back down if displayed on screen. But is not recommended, and simply a waste.



来源:https://stackoverflow.com/questions/4232303/problem-about-2x

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