【问题标题】:How to clip image with another image in CGContext?如何在 CGContext 中用另一个图像剪辑图像?
【发布时间】:2012-08-19 15:49:56
【问题描述】:

我想用两张图片得到以下结果。

请帮帮我。

【问题讨论】:

    标签: iphone ios cgcontext masking clipping


    【解决方案1】:

    要在一个图像视图上组合两个图像,试试这个

    UIImage *bottomImage = [UIImage imageNamed:@"bottom.png"]; //background image
    UIImage *image       = [UIImage imageNamed:@"top.png"]; //foreground image
    CGSize newSize = CGSizeMake(width, height);
    UIGraphicsBeginImageContext( newSize );
    // Use existing opacity as is
    [bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    // Apply supplied opacity if applicable
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    newImage 添加到 UIImageView

    【讨论】:

    • 感谢您的回答。但是请仔细看图片,噪点只画在鞋底部分。
    • 请在完成上述代码后按照@Prince的回答,屏蔽图像以获得所需的解决方案
    【解决方案2】:

    在@Sumanth 的合并两个图像的代码之后,您需要屏蔽最终图像,如how-to-mask-an-image 链接

    【讨论】:

      猜你喜欢
      • 2019-12-25
      • 2015-02-15
      • 1970-01-01
      • 2011-01-29
      • 2014-03-08
      • 2021-03-28
      • 2015-03-14
      • 2016-05-27
      相关资源
      最近更新 更多