2013-02-08 164 views
1

,如果你想捕捉的屏幕iOS應用,您可以使用下面的代碼:屏幕捕捉與幀

UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
currentCaptureImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

,但我想捕捉從一個特定的角度,例如圖片(start.x,start.y)以及特定的寬度和高度,我該怎麼做?

回答

0

我只是谷歌,並得到最好的答案從How to capture a specific size of the self.view

UIGraphicsBeginImageContextWithOptions(CGSizeMake(300, 320), YES, 0.); 
    [self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

如果你的觀點是,例如,600x320和你想捕捉的寬度,中間300點,你會翻譯上下文150點向左:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(300, 320), YES, 0.); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextTranslateCTM(context, -150.f, 0.f); 
    [self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext();