我试图获取屏幕截图,但我的结果图片有点模糊。我该如何解决它并使其更清晰?
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 :(得分:0)
看看那些;
UIScreen.mainScreen().bounds.height - 80) UIScreen.mainScreen().bounds.height - 145))
windowImage.drawAtPoint(CGPoint(x: -0, y: -65))
仔细检查并更改80和145以及-0,-65我认为它们在主屏幕高度上有所不同。
由于
答案 1 :(得分:0)
您希望将<{1}}用于图像上下文的 ,并在两者中指定设备屏幕的比例(或只需输入UIGraphicsBeginImageContextWithOptions()
以允许Core Graphics自动检测屏幕比例。)
0.0
默认为UIGraphicsBeginImageContext()
,因此您可以在第一个上下文中有效地绘制高分辨率图像,然后在第二个上下采样。</ p>