如何将视图内容转换为图像格式?

时间:2010-12-16 12:38:17

标签: objective-c cocoa ipad

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未声明。

对此有何解决方案?

感谢你。

1 个答案:

答案 0 :(得分:0)

我不确定,但我发现this link,对我这样的程序员可能会有所帮助。大多数主题都包括在内。看看它。感谢。