2013-02-02 3 views
1

제목으로 말하면 내 앱의 잘린 스냅 사진을 찍어야한다고합니다.일부 부분을 자른 후 화면의 스냅 샷 찍기

캡쳐 화면을 약간 잘라내고 싶습니다. (% 20) 저는 이미 스냅 샷을 찍어서 페이스 북과 그것의 작업으로 보내는 코드를 가지고 있습니다. 내 코드는 화면의 % 20 %를 무시하도록 말할 수 있습니다. 높이와 너비가 맞는지 또한 스택 오버플로에서 몇 가지 질문을 보았고 스크린 샷을 슬라이드하여 최상위에서 원치 않는 부분을 없애 버렸습니다. 아래쪽 거대한 흰색 영역이 나타나서 내 문제를 해결하지 못했습니다. 여기

은 다음과 같이 사용

- (UIImage *)cropImage:(UIImage *)imageToCrop toRect:(CGRect)rect 
    {  
     CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect); 
     UIImage *cropped = [UIImage imageWithCGImage:imageRef]; 
     CGImageRelease(imageRef); 

     return cropped; 
    } 

에 대한 이미지를 자르려면 어떤 프레임을 받아 내 스냅 샷 코드

UIGraphicsBeginImageContext(self.ekran.bounds.size); 
    [self.ekran.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

답변

0

이미지를 잘라하는 방법입니다 :

UIGraphicsBeginImageContext(self.ekran.bounds.size); 
[self.ekran.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

CGFloat imgHight = resultingImage.size.height; 

// Create a frame that crops the top 20% of the image 
CGRect* imageFrame = CGRectMake(0, imgHight - (imgHight*0.8), width, imgHight*0.8); 

resultingImage = [self cropImage:resultingImage toRect:imageFrame]; 
+0

덕분에 그걸 시도 할께 ... –