iOS多张图片合成

- (UIImage *)imagesSynthesis{
    UIImage * bgImg = [UIImage imageNamed:@"picsWall_bg.jpg"];
    UIImage * img1  = [UIImage imageNamed:@"1.png"];
    UIImage * img2  = [UIImage imageNamed:@"2.png"];
    UIImage * img3  = [UIImage imageNamed:@"3.png"];
    UIImage * img4  = [UIImage imageNamed:@"4.png"];
    UIImage * img5  = [UIImage imageNamed:@"5.png"];
    UIImage * img6  = [UIImage imageNamed:@"6.png"];
    
    // 得到图片绘制上下文,指定绘制区域
    UIGraphicsBeginImageContext(CGSizeMake(640, 1136));
    
    // 背景图
    [bgImg drawInRect:CGRectMake(0, 0, 640, 1136)];
    // img1
    [img1 drawInRect:CGRectMake(128, 136, 160, 110)];
    // img2
    [img2 drawInRect:CGRectMake(428, 136, 94, 110)];
    // img3
    [img3 drawInRect:CGRectMake(128, 378, 160, 110)];
    // img4
    [img4 drawInRect:CGRectMake(418, 380, 94, 220)];
    // img5
    [img5 drawInRect:CGRectMake(128, 618, 160, 230)];
    // img6
    [img6 drawInRect:CGRectMake(422, 728, 94, 120)];
    
    // 从当前图片上下文中得到image
    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return resultingImage;
}
iOS多张图片合成_第1张图片
合成前背景图
iOS多张图片合成_第2张图片
合成后图片

版权声明:出自MajorLMJ技术博客的原创作品 ,转载时必须注明出处及相应链接!

你可能感兴趣的:(iOS多张图片合成)