Tôi đã vẽ thành CGContext của UIView.Làm cách nào để lưu những gì tôi đã vẽ trong CGContext
- (void)drawRect:(CGRect)rect {
[self drawInContext:UIGraphicsGetCurrentContext()]
}
Tôi muốn lưu những gì tôi đã vẽ vào tệp png.
Có giải pháp đơn giản nào không?
EDIT: Dựa trên gợi ý dưới đây - đây là những gì tôi có cho đến nay ....
-(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];
}
có thể là một điều tốt hơn để hỏi là làm thế nào để tạo ra một bối cảnh bitmap và phát lại các bản vẽ của tôi vào đó. – sylvanaar