开发者

getting png image from context but view color changing

开发者 https://www.devze.com 2023-02-27 11:07 出处:网络
hi all i am using below code to get png formated image from the context and saving into particular path.

hi all i am using below code to get png formated image from the context and saving into particular path.

- (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];

 }

here my problem is after getting the image from the above code my view color is changing f开发者_如何转开发rom normally available color(which is before creating png) to entirely black color can any one give me the exact reason why it is happening Thanks in advance.


See 4 line of code getting png image from Context.

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

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消