HI,
我使用以下代码将视图转换为图像格式:
- (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未声明。
然后在data = [rep representationUsingType:NSPNGFileType properties:properties];
行,我得到NSPNGFileType未声明。
对此有何解决方案?
感谢你。