我已经绘制到 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];
}
最佳答案
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:@"image.png"];
关于iphone - 如何将绘制的内容保存在 CGContext 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2568421/