Wciągnąłem CGContext z UIView.Jak zaoszczędzić to, co rysowałem w CGContext
- (void)drawRect:(CGRect)rect {
[self drawInContext:UIGraphicsGetCurrentContext()]
}
Chciałbym zapisać to, co narysowałem, do pliku PNG.
Czy istnieje proste rozwiązanie?
EDIT: W oparciu o sugestie poniżej - oto co mam tak daleko ....
-(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];
}
może lepszym rozwiązaniem jest poprosić o jak stworzyć kontekst bitmapy i odtworzyć swoje rysunki do tego. – sylvanaar