我在 iphone 上工作,我使用 UIView 的子类,在 draw rect 方法中我正在做一些设计。我想将此 View 转换为 .png 格式。
提前致谢。
最佳答案
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];
关于iphone - 将 uiview 转换为 .png 图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10748669/