2013-07-17 1 views
1

보기의 스크린 샷을 찍고 해당 이미지를 문서 폴더에 저장하는 앱이 있습니다.iPhone에서보기의 스크린 샷을 찍는 동안 메모리가 거의 사용되지 않음

다음 코드를 사용하고 있습니다.

CGSize size = self.view.bounds.size; 
    CGRect cropRect; 
    CGRect screenBounds = [[UIScreen mainScreen] bounds]; 
    if([self isPad]) 
    { 
     cropRect = CGRectMake(145, 110, 476, 476); 
    } 
    else 
    { 
     if (screenBounds.size.height ==568) 
     { 

      cropRect = CGRectMake(40, 69, 240, 240); 
     } 

     else 
     { 
      cropRect = CGRectMake(40, 62, 240, 240); 
     } 
    } 

    /* Get the entire on screen map as Image */ 
    UIGraphicsBeginImageContext(size); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

    UIImage * mapImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    /* Crop the desired region */ 
    CGImageRef imageRef = CGImageCreateWithImageInRect(mapImage.CGImage, cropRect); 
    UIImage * cropImage = [UIImage imageWithCGImage:imageRef]; 
    CGImageRelease(imageRef); 

    /* Save the cropped image 
    UIImageWriteToSavedPhotosAlbum(cropImage, nil, nil, nil);*/ 

    //save to document folder 
    NSData * imageData = UIImageJPEGRepresentation(cropImage, 1.0); 
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString* documentsDirectory = [paths objectAtIndex:0]; 

     imagename=[NSString stringWithFormat:@"Fff.jpg"]; 

    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imagename]; 
    ////NSLog(@"full path %@",fullPathToFile); 
    [imageData writeToFile:fullPathToFile atomically:NO]; 

내가 스크린 샷을 15 ~ 20 시간이 걸릴 경우 잘 작동하지만 그것은 나에게 메모리 부족 경고 및이 코드에 그 후 응용 프로그램 충돌을 준다 후.

이러한 메모리 문제가 발생하지 않는 더 최적화 된 코드가 있습니까?

도와주세요. 당신의 reply.This 방법 뷰의 특정 부분을 자르려면 나에게 전체 뷰의 스크린 샷 만 줄 것 내 우는 방법

답변

1

캡처 화면 ..

- (UIImage *)captureView { 

    //hide controls if needed 
    CGRect rect = [self.view bounds];// Here define CGRect with your requirement of take screenshot of some part 

    UIGraphicsBeginImageContext(rect.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    [self.view.layer renderInContext:context]; 
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return img; 

} 

내 다른 답변 howe-to-capture-uiview-top-uiview

+0

감사를 참조하십시오 ? 위 코드에서 볼 수 있듯이 일부 뷰만 가져 가고 싶습니다. – Manthan

+0

그냥'[self.view bounds]; 대신 프레임이나 rect를 설정하십시오. –

+0

당신이 어떤 아이디어를 가지고 있다면 도와주세요 ** http : //stackoverflow.com/questions/17745058/ftp-downloading-very- 느린 - 아이폰 **. @Paras Joshi – Manthan

관련 문제