【问题标题】:iOS: How to take snapshot of UIView which has rounded corners? [duplicate]iOS:如何拍摄具有圆角的 UIView 的快照? [复制]
【发布时间】:2017-09-13 12:25:32
【问题描述】:

我想将 UIView 的快照作为 PNG 图像。在我的情况下,视图具有圆角,因此,当我拍摄快照时,它会显示边缘为圆形的黑色。我希望它是透明的。我怎样才能做到这一点?

这是我用来获取图像的代码。

- (UIImage *)snapshotOfQuoteContainerView {

UIGraphicsBeginImageContextWithOptions(self.outerContainerView.bounds.size, YES, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.outerContainerView.layer renderInContext:context];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return snapshotImage;
}

注意:After changing image size, image's transparent part became black 没有解决我的问题。就我而言,它与更改图像大小无关。

【问题讨论】:

  • 显示。您的。代码。
  • 代码在哪里?
  • 添加源代码。
  • 显示您的 outerContainerView 属性。你设置 UIView 的 "clipsToBound=YES" 属性了吗?
  • 是,设置为是​​。我也试过没有。它没有帮助。

标签: ios uiview


【解决方案1】:

UIGraphicsBeginImageContextWithOptions 的第二个参数是opaque。你提供YES,但你需要NO

不透明

一个布尔标志,指示位图是否不透明。如果你 知道位图完全不透明,指定 YES 忽略 alpha 通道并优化位图的存储。指定 NO 意味着 位图必须包含一个 alpha 通道来处理任何部分 透明像素。

延伸阅读:https://developer.apple.com/documentation/uikit/1623912-uigraphicsbeginimagecontextwitho?language=objc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    相关资源
    最近更新 更多