Able to capture UIImage as-is based on content mode from UIimageView?

天涯浪子 提交于 2019-12-02 16:44:55

问题


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!


回答1:


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:



来源:https://stackoverflow.com/questions/23446358/able-to-capture-uiimage-as-is-based-on-content-mode-from-uiimageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!