温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

iOS合成图片

发布时间:2020-08-01 21:18:02 来源:网络 阅读:990 作者:fightFromNow 栏目:移动开发

iOS进行合成方式,本人知道的又两种:

1:使用UIImage直接合成

      方法:通过上下文将要合成的图片都绘制到该上下文,然后得到合成的图片

- (UIImage*)NTESATCOverlayWith:(UIImage*)overlayImage{

UIGraphicsBeginImageContext(self.size);

    

[self drawAtPoint:CGPointZero];

[overlayImage drawInRect:CGRectMake(0, 0, self.size.width, self.size.height) blendMode:kCGBlendModeNormal alpha:0.9999999];

    

UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return combinedImage;

}

2:通过UIView进行

     方法:将图片都加载到一个UIView上,然后通过UIView生成图片.

- (UIImage *) p_w_picpathFromView:(UIView *)view {

// we need to size the graphics context according to the device scale

    CGFloat scale = [[UIScreen mainScreen] scale];  

    CGSize pageSize = view.frame.size;

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGContextRef context = CGBitmapContextCreate(NULL,

                                                 pageSize.width*scale,

                                                 pageSize.height*scale,

                                                 8,                     /* bits per component*/

                                                 pageSize.width*scale * 4,  /* bytes per row */

                                                 colorSpace,

                                                 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrderDefault);

    

    CGColorSpaceRelease(colorSpace);

    CGContextClipToRect(context, CGRectMake(0, 0, pageSize.width*scale, pageSize.height*scale));

    

    CGContextScaleCTM(context, scale, scale);

    

    [view.layer renderInContext:context];

    

    

    CGImageRef p_w_picpath = CGBitmapContextCreateImage(context);

    CGContextRelease(context);

    

    UIImage *destImaage = [UIImage p_w_picpathWithCGImage:p_w_picpath scale:1 orientation:UIImageOrientationDown | UIImageOrientationDownMirrored];

    CGImageRelease(p_w_picpath);

    return destImaage;

}



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI