【问题标题】:How to delete a rect in a UIImage on iOS?如何在 iOS 上删除 UIImage 中的矩形?
【发布时间】:2012-04-30 09:55:10
【问题描述】:

如何删除 UIImage 中的矩形区域?我的想法是我有一个纯色图像和一个 CGRect 矩形,我想删除 UIImage 中的 CGrect,以便 CGRect 区域是透明的。请参考下图。半红色是我的 uiimage,我想删除中间的矩形,以便我可以透明地查看背景图像。

【问题讨论】:

    标签: ios xcode uiimageview mask


    【解决方案1】:
    UIImage *yourImage;
    CGRect imageRect = CGRectMake(0, 0, yourImage.size.width, yourImage.size.height);
    CGRect grayRect = CGRectMake(20, 20, 20, 20);
    CGRect rects[2] = {
      imageRect,
      grayRect
    };
    CGContextClipToRects(context, rects, 2);
    [yourImage drawInRect:imageRect];
    

    【讨论】:

      【解决方案2】:

      CGContextClearRect(context, your_rect)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-14
        相关资源
        最近更新 更多