清晰版:
UIGraphicsBeginImageContextWithOptions(bgView.bounds.size,NO, 0.0); //代替UIGraphicsBeginImageContext(bgView.bounds.size)方法
CGContextRef context =UIGraphicsGetCurrentContext();
[bgView.layerrenderInContext:context];
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image,nil, nil,nil);//然后将该图片保存到图片图
模糊版:UIGraphicsBeginImageContext(bgView.bounds.size); //currentView当前的view 创建一个基于位图的图形上下文并指定大小(截取ios7之前的分辨率)
[bgView.layer renderInContext:UIGraphicsGetCurrentContext()];//renderInContext呈现接受者及其子范围到指定的上下文
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();//返回一个基于当前图形上下文的图片
UIGraphicsEndImageContext();//移除栈顶的基于当前位图的图形上下文
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);//然后将该图片保存到图片图
本文详细介绍了在iOS开发中使用UIGraphicsBeginImageContextWithOptions方法进行图片截取,并通过UIGraphicsGetCurrentContext和UIGraphicsGetImageFromCurrentImageContext进行渲染和获取图片,最后使用UIImageWriteToSavedPhotosAlbum方法将图片保存到相册的具体步骤和实现细节。同时,提供了清晰版与模糊版的代码对比,帮助开发者理解关键操作和优化策略。
298

被折叠的 条评论
为什么被折叠?



