안녕하세요,보기의 내용을 이미지 형식으로 변환하는 방법은 무엇입니까?
이미지 형식으로보기를 변환하려면 다음 코드를 사용하고 있습니다 :
- (void)printViewToPNG
{
NSData *data;
NSBitmapImageRep *rep;
NSDictionary *properties;
rep = [self bitmapImageRepForCachingDisplayInRect:[self frame]];
[self cacheDisplayInRect:[self frame] toBitmapImageRep:rep];
data = [rep TIFFRepresentation];
properties = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:NSImageInterlaced];
data = [rep representationUsingType:NSPNGFileType properties:properties];
[data writeToFile:[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/test.png"] atomically:YES];
}
그러나 그것은 나를 NSBitmapImageRep 및 NSImageInterlaced 오류를 제공합니다. 클래스 프레임 워크 Appkit.framework를 사용했지만 오류를 제거하는 데 도움이되는 특정 클래스를 얻지 못했습니다.
업데이트 : 다음과 같은 오류가 발생합니다. NSBitmapImageRep & NSImageInterlaced uneclared. 다음 data = [rep representationUsingType:NSPNGFileType properties:properties];
줄에 NSPNGFileType 가져 오지 못했습니다.
이것에 대한 해결책은 무엇입니까?
감사합니다.
정확한 오류는 무엇입니까? –
코드가 나를 위해 컴파일됩니다 (실제로는 원하는대로 수행 할 수 없습니다). GUI 앱을 만들려면 AppKit을 추가하지 않아도됩니다. 어떤 유형의 프로젝트를 구축하고 있습니까? Apple의 프로젝트 템플릿으로 시작 했습니까? 프로젝트를 어떻게 만들지 않았습니까? –
늦게 답장을 드려 죄송합니다. 실제로 필자는 pdf 페이지를 이미지로 변환해야하고 그 과정에서 위의 코드에서 오류가 발생합니다. 어떤 해결책? – Sarah