【发布时间】:2013-06-13 06:15:58
【问题描述】:
首先我在UIImageView 上添加UILable,然后在我截取UIView 之后,图像无法正确捕获UIView 框架我还附上了图像网址。
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 与源图像的大小相同吗?如果不是,那么您是否将 UIImage 添加到您的视图而不更改其大小?你确定吗? :) 'Couse 如果你有一个大小为 200x500 的图像,但你在大小为 300x700 的 UIView 上绘制它,允许 UIView 拉伸图像以使其占据所有空间,那么你将获得 UIView 大小的屏幕截图,而不是源图片
-
当我将捕获的图像保存在照片库中时,日期显示不正确
-
啊,好的,现在知道了。尝试在此处查看我的答案:stackoverflow.com/questions/16062974/… 有一个完全可用的代码供您使用
-
使用性能更好的API回答stackoverflow.com/questions/4334233/…
标签: ios objective-c ios6 swift3