能否根据 UIimageView 的内容模式按原样捕获 UIImage?

Able to capture UIImage as-is based on content mode from UIimageView?(能否根据 UIimageView 的内容模式按原样捕获 UIImage?)
本文介绍了能否根据 UIimageView 的内容模式按原样捕获 UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以捕获 UIImage,因为它在 UIImageView 中显示为 as-is,基于其 <代码>内容模式.例如,如果我将 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::p>

I was wondering if there is a way to capture an UIImage as it appears as-is viewed in an UIImageView based on its contentMode. For example, if I pass a 3:4 aspect ratio to a square UIImageView, and use "Aspect Fit" as the contentMode, then I'd expect to see white letterboxes in the left and right parts the image to fill out the square. Would it then be possible to take whatever appears and save it directly as an new UIImage with the letter boxing?

Thanks!

解决方案

You can capture a "screen shot" of the way a UIImageView is actually displayed by calling CALayer's renderInContext: method.

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

这篇关于能否根据 UIimageView 的内容模式按原样捕获 UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)