Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert uiview to .png image

I am working on iphone and I take the subclass of UIView and in draw rect method I am making some design. I want to convert this view in .png format.

Thanks in advance.

like image 447
Chandni Avatar asked May 25 '12 04:05

Chandni


1 Answers

    UIGraphicsBeginImageContext(myView.frame.size);
    [myView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData *data=UIImagePNGRepresentation(viewImage);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *strPath = [documentsDirectory stringByAppendingPathComponent:@"myimage.png"];
    [data writeToFile:strPath atomically:YES];
like image 160
Dhaval Panchal Avatar answered Oct 04 '22 04:10

Dhaval Panchal