Iphone 从上下文获取png图像,但查看颜色更改

Iphone 从上下文获取png图像,但查看颜色更改,iphone,objective-c,ipad,png,Iphone,Objective C,Ipad,Png,嗨,我正在使用下面的代码从上下文中获取png格式的图像并保存到特定路径中 - (void)drawRect:(CGRect)rect { UIGraphicsBeginImageContext(self.bounds.size); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 0.2); for(id

嗨,我正在使用下面的代码从上下文中获取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之前)更改为完全黑色。有人能告诉我发生这种情况的确切原因吗
提前谢谢

请参阅从上下文获取png图像的4行代码

UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

谢谢

请参阅从上下文获取png图像的4行代码

UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

谢谢

在写入文件之前检查
imageData
是否有效是它在路径中的显示方式在写入文件之前检查
imageData
是否有效是它在路径中的显示方式path@AAAAAAAAA:选中此项可对CGContextSetRGBFillColor添加注释function@AAAAAAAAA:勾选以发表评论CGContextSetRGBFillColor函数