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;
}
合成前背景圖
合成后圖片

版權聲明:出自MajorLMJ技術博客的原創作品 ,轉載時必須注明出處及相應鏈接!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容