2016-02-14 44 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的比例尺,所以您可以在第一個上下文中高效地繪製高分辨率圖像,然後在第二個上下文中對其進行下采樣。