从上下文中获取png图像,但视图颜色改变

| 大家好,我正在用下面的代码从上下文中获取png格式的图像并保存到特定路径中。
- (void)drawRect:(CGRect)rect {
UIGraphicsBeginImageContext(self.bounds.size);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 0.2);
for(id rects in textRects){

    CGRect rect = [rects CGRectValue];
CGContextFillRect(UIGraphicsGetCurrentContext(), rect); 
}
CGContextStrokePath(UIGraphicsGetCurrentContext());
textImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();
NSData *imageData=UIImagePNGRepresentation(textImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path=[documentsDirectory stringByAppendingPathComponent:@\"folder\"];


[imageData writeToFile:[path stringByAppendingPathComponent:@\"/subfolder/assets/0.png\"] atomically:YES];

 }
这是我的问题是从上述代码获取图像后,我的视图颜色从通常可用的颜色(在创建png之前)变为全黑,任何人都可以给我确切原因的原因 提前致谢。
已邀请:
请参阅第4行代码从Context获取png图像。
UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
谢谢

要回复问题请先登录注册