2012-03-15 49 views
1

我試圖保存我iPhone屏幕的屏幕截圖,但結果是以1x的比例出現。iPhone iOS如何使用不同的分辨率或比例渲染截圖?

例如一個320x480像素的屏幕截圖是320x480像素,當顯示在視網膜顯示屏上時,它看起來很模糊。但是,如果我使用主屏幕和電源按鈕進行截圖,則生成的圖像爲640x960,並且在視網膜顯示屏上看起來很完美。 如何在考慮屏幕比例因子的情況下拍攝屏幕截圖?

謝謝!

+0

如果沒有家和電源按鈕,你還會如何截取屏幕截圖? – Snowman 2012-03-15 04:20:53

+0

以編程方式。但這應該是本質上完全解決的。 – JoePasq 2012-03-15 04:26:54

回答

2
Try This: 

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) 
     UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale); 
    else 
     UIGraphicsBeginImageContext(self.window.bounds.size); 

    [self.window.layer renderInContext:UIGraphicsGetCurrentContext()]; 
     UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
     NSData * data = UIImagePNGRepresentation(image); 
     [data writeToFile:@"foo.png" atomically:YES]; 
相關問題