ios - 能够根据 UIimageView 的内容模式按原样捕获 UIImage 吗?

标签 ios iphone uiimageview uiimage crop

我想知道是否有一种方法可以捕获 UIImage,因为它在 UIImageView 中显示为原样,基于其 内容模式。例如,如果我将 3:4 纵横比传递给正方形 UIImageView,并使用“Aspect Fit”作为 contentMode,那么我期望在图像的左右部分看到白色信箱以填充正方形。那么是否可以将出现的任何内容直接保存为新的带有信箱的 UIImage

谢谢!

最佳答案

您可以通过调用 CALayer 的 renderInContext: 方法捕获 UIImageView 实际显示方式的“屏幕截图”。

https://developer.apple.com/library/ios/documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instm/CALayer/renderInContext :

关于ios - 能够根据 UIimageView 的内容模式按原样捕获 UIImage 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23446358/

相关文章:

ios - Phonegap iOS 版本不显示背景图片

iphone - MapView:使用MKUserTrackingBarButtonItem切换 map 跟踪状态

iphone - SalesForce 上的 SSL 证书/流式 API

iphone - 如何从子类正确设置父类(super class)属性

ios - 分配有效的 UIImage 后,UIImageView.image 始终为 nil

ios - UIImageView 无法以编程方式更改位置

ios - iOS UIImageView 和 App 进入后台的奇怪行为

ios - iOS 设备的总 RAM 大小

ios - 如何使用 Apple HealthKit 获得每日 sleep 时长?

ios - 我需要从我的应用程序中访问 IOS 联系人。