문제

스크린 샷을 스프레이트 키트에서 잡으려고 할 때.나는 온라인에서 찾을 수있는 모든 방법을 시도했습니다.그들은 작동하지 않습니다.

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *gameOverScreenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
.

그냥 작동하지 않음

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
.

캔트는 self.bounds와 scale을 인식합니다.

도움이 되었습니까?

해결책

나는 SKVIEW (나는 그렇다고 가정)로서의 -drawViewHierarchyInRect:afterScreenUpdates:가 skview (나는 그렇게 가정)로 작용 해야하는지 확실하지 않지만, 두 번째 예제가 컴파일되지 않는 이유는 (1) bounds에서 self를 호출하려고 시도하는 것입니다 (아마도UIViewController와 uiviewController) self.view 및 (2) scale의 값을 정의하지 않은 것입니다.그 두 줄을 변경하십시오 :

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
.

또한, "불투명"을위한 제 2 파라미터는 "불투명"이 아닌 경우에 "AfterscreenUpdates"를 yes로 설정하는 것이 아니라 "AfterscreenUpdates"를 설정하지 않는 경우에만이를 포함하지 않는 경우에만 필요하지 않습니다.이러한 성능을 변경하여 더 나은 성능을 볼 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top