2012-03-27 5 views
1

이 코드를 사용하여 내 화면을 캡처하고 있습니다.일부 아이폰 화면 캡처

 CGImageRef screen = UIGetScreenImage(); 
    UIImage* image = [UIImage imageWithCGImage:screen]; 
    CGImageRelease(screen); 
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 

이 코드는 화면을 모두 차지합니다. 그 중 일부만 필요합니다 ... CGRect rect = CGRectMake (0,0,100,100);

매개 변수를 전달하려면 어떻게해야합니까?

감사합니다.

답변

1

UIImage를 자르거나 자르고 싶다는 소리가 들립니다.

이 관련 문제의 코드를 밖으로

확인하고 당신을 할 수 있는지 :

How to crop the UIImage?

+0

특정 크기로 uiimage를 가져올 수 없습니까? – OAZ

4

당신은 또한 RECT 크기에 대한 새로운 컨텍스트를 정의 할 수 있습니다 당신이 원하는 :

CGRect rect = CGRectMake (0,0,100,100); 
UIGraphicsBeginImageContext(rect); 
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageWriteToSavedPhotosAlbum(screenshot, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 

참고 : 가져 오기에 QuartzCore를 추가해야합니다.

#import <QuartzCore/QuartzCore.h> 

을 사용하면 메인 뷰를 얻을 수 있습니다.

+0

이렇게 최고 수준의 뷰를 얻는 것이 매우 도움이되었습니다. 감사합니다! –

1

이 코드를 사용하여 화면을 캡처하고 아이폰 장치의 이미지 라이브러리에 자동으로 저장합니다.

UIGraphicsBeginImageContext(self.view.frame.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);