2013-01-11 3 views

답변

4

기본 해상도

CGRect rect = [captureView bounds]; 
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
[captureView.layer renderInContext:context]; 
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

이 JPG에있는 UIImage 저장에이 코드 캡처에게 UIView의 시도 전체 화면 스크린 샷에 대한 다음 코드 (키 윈도우)

UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; 
CGRect rect = [keyWindow bounds]; 
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
[keyWindow.layer renderInContext:context]; 
UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

시도 형식으로 응용 프로그램의 문서 폴더에서 95 %의 품질로 할 수 있습니다.

NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/capturedImage.jpg"]];  
[UIImageJPEGRepresentation(capturedImage, 0.95) writeToFile:imagePath atomically:YES]; 

출처 : How Do I Take a Screen Shot of a UIView?