【发布时间】:2010-04-02 18:31:33
【问题描述】:
我已绘制到 UIView 的 CGContext 中。
- (void)drawRect:(CGRect)rect {
[self drawInContext:UIGraphicsGetCurrentContext()]
}
我想将我绘制的内容保存到 png 文件中。
有简单的解决办法吗?
编辑:根据以下建议 - 这是我目前所拥有的......
-(void)createImage {
NSString* outFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.png"];
DLog(@"creating image file at %@", outFile);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:outFile
atomically:NO];
}
- (void)drawRect:(CGRect)rect {
[self drawInContext:UIGraphicsGetCurrentContext()];
[self createImage];
}
【问题讨论】:
-
或许更好的问题是如何创建位图上下文并将我的绘图重播到其中。
标签: iphone cocoa-touch uiview