关于将两张图片的颜色揉合

//官方文档:https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_images/dq_images.html   

步骤:

  1. 创建文件继承UIView就行

  2. 实现 - (void)drawRect:(CGRect)rect 方法


#import "TLLView.h"


@implementation TLLView

- (void)drawRect:(CGRect)rect {

    CGContextRef context = UIGraphicsGetCurrentContext();

    UIImage * backimage = [UIImage imageNamed:@"image1"];

    CGRect imageRect = CGRectMake(50, 100, 300, 200);

    drawImage(context, [backimage CGImage], imageRect);

    

    UIImage * foreImage = [UIImage imageNamed:@"image2.jpg"];

    

    CGContextSetBlendMode(context, kCGBlendModeColorDodge);    

    drawImage(context, [foreImage CGImage], CGRectMake(50, 100, 50, 50));


// PS:先画image1与先画image2 的效果是不一样的; drawImage 方法是为了将图片画正,不然直接画出的图片是倒着的(有兴趣可以去研究);

}


void drawImage(CGContextRef context, CGImageRef image , CGRect rect){

    CGContextSaveGState(context);

    

    CGContextTranslateCTM(context, rect.origin.x, rect.origin.y);

    CGContextTranslateCTM(context, 0, rect.size.height);

    CGContextScaleCTM(context, 1.0, -1.0);

    CGContextTranslateCTM(context, -rect.origin.x, -rect.origin.y);

    CGContextDrawImage(context, rect, image);

    

    CGContextRestoreGState(context);

}


效果如下:

image1:

131358_ob4V_2517666.jpg

image2:

131358_oBCV_2517666.jpg

效果图:

131630_bvHr_2517666.png

转载于:https://my.oschina.net/iOStianlele/blog/610307

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值