2016-02-14 47 views
0

我试图获得截图,但是我的结果图像有点模糊。我该如何解决它并使其更加清晰?为什么我用Swift获得屏幕截图模糊?

let window = UIApplication.sharedApplication().delegate!.window!! 
UIGraphicsBeginImageContextWithOptions(CGSize(width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height - 80), true, UIScreen.mainScreen().scale) 
window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: true) 
let windowImage = UIGraphicsGetImageFromCurrentImageContext() 
UIGraphicsEndImageContext() 
UIGraphicsBeginImageContext(CGSize(width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height - 145)) 
windowImage.drawAtPoint(CGPoint(x: -0, y: -65)) 
let croppedImage: UIImage = UIGraphicsGetImageFromCurrentImageContext() 
UIGraphicsEndImageContext(); 

UIImageWriteToSavedPhotosAlbum(croppedImage, nil, nil, nil) 

这是我的代码

+0

@dasblinkenlight,但我已经设置了我自己的决议。没有? –

+0

@dasblinkenlight我甚至将刻度设置为'0.0' –

+0

@dasblinkenlight不,我没有。但在'0'的情况下,它将等于'0'。这就是为什么在我的问题,我采取了screen.scale。为什么你问过它? –

回答

0

看,多数民众赞成;

UIScreen.mainScreen().bounds.height - 80) UIScreen.mainScreen().bounds.height - 145)) 
windowImage.drawAtPoint(CGPoint(x: -0, y: -65)) 

仔细检查和更改80和145和-0,-65我认为不同他们在你的主屏幕高度。

感谢

0

你想使用UIGraphicsBeginImageContextWithOptions()的图像上下文,并指定设备屏幕的同时在规模(或只是输入0.0允许核芯显卡进行自动检测屏幕比例)。

UIGraphicsBeginImageContext()默认为1.0的比例尺,所以您可以在第一个上下文中高效地绘制高分辨率图像,然后在第二个上下文中对其进行下采样。