OS 7 has a new method that allows you to draw a view hierarchy into the current graphics context. This can be used to get an UIImage very fast.
I implemented a category method on UIView to get the view as an UIImage:
- (UIImage *)pb_takeSnapshot { UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale); [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; // old style [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }
It is considerably faster then the existing renderInContext: method.
Reference : https://developer.apple.com/library/ios/qa/qa1817/_index.html
UPDATE FOR SWIFT: An extension that does the same:
extension UIView { func pb_takeSnapshot() -> UIImage { UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, UIScreen.mainScreen().scale); self.drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true) // old style: self.layer.renderInContext(UIGraphicsGetCurrentContext()) let image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } }
相关推荐
c#截取一张图片的部分 或者缩放图片,教你如何加工原始的图片,变成你想要的效果
.net上传图片并在线截取图片,网页中上传图片并截取图片大小,跟QQ上传头像,并截取大小类似
通过jquery的两个插件实现图片截取效果,上传 后台实现图片根据截取出来的位置坐剪切 压缩 可以配合图片缓存的数据库做的接口实现图片服务器做iframe 跨域上传
使用java applet开发,指定要截取的屏幕范围,保存成图片到客户端的小应用程序。
js 截取图片代码
高仿微信demo,内含截取本地图片,截取手机拍照图片作为头像
jquery图片截取DEMO,jquery图片截取DEMO
android 框选 图片 截取
该工具类用于java代码对图片的截取,按照上下左右边距的百分比截取,然后返回被截取之后图片信息的byte数组,用户可以将byte数组,用fileoutputStream保存在指定的目录
图片截取DEMO...截取图片
ffmpeg-php-win32-all.zip 视频截取图片
客户端截取页面内容,转为图片并显示。
截取当前视图
JS实现:鼠标操作的,方框截取图片部分内容,只有截图部分,入股有其他功能,可以再叠加
jquery 上传图片时截取固定大小的范围图片 类似QQ上传头像截取,17年用的了 当时亲自测试用过还不错
javascript实现图片截取功能,实现网站头像的制作功能!!
选择你感兴趣的区域,截取图片,然后下一步对你感兴趣的区域继续进行操作
人脸识别代码实现,截取图片脸部进行检测人脸识别代码实现,截取图片脸部进行检测 人脸识别代码实现,截取图片脸部进行检测人脸识别代码实现,截取图片脸部进行检测 人脸识别代码实现,截取图片脸部进行检测人脸识别...
1.对图片进行缩放处理2.截取图片中的一部分3.将图片缩放并嵌入到另一张纯色图片中4.图片添加水印:添加图片水印和文字水印5.控制Jpg图片的输出质量6.将文本信息隐藏在图片文件中(建议使用BMP图片)
C# WinForm源代码,可以实现定时截取当前屏幕,然后存为本地图片,再将其上传至远程服务器端,上传图片到服务器。也包含上传文件到服务器端的方法。通过Ftp协议上传,更改源代码中ftp中IP地址、用户名及密码即可使用...