首先我在UI
ImageView上添加UILable,然后在屏幕截图UIView之后,图像不正确地捕获UIView Frame我也附加了图像url.
2) After Capture the image Link :-
代码: –
UIGraphicsBeginImageContext(viewImage.frame.size); [viewImage.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *vwImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData *data=UIImagePNGRepresentation(vwImage); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // NSString *imgName = [NSString stringWithFormat:imagename]; NSString *strPath = [documentsDirectory stringByAppendingPathComponent:imagename]; [data writeToFile:strPath atomically:YES];
解决方法
您可以拍摄任何UIView的屏幕截图或捕获任何UIView,并将其保存为具有以下代码的图像.
- (UIImage *)captureView { //hide controls if needed CGRect rect = [self.view bounds]; UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); [self.view.layer renderInContext:context]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; }