(IOS)合并两个图片

+ (UIImage*)mergeImage:(UIImage*)firstImage withImage:(UIImage*)secondImage {

    CGImageReffirstImageRef = firstImage.CGImage;

    CGFloatfirstWidth =CGImageGetWidth(firstImageRef);

    CGFloatfirstHeight =CGImageGetHeight(firstImageRef);

    CGImageRefsecondImageRef = secondImage.CGImage;

    CGFloatsecondWidth =CGImageGetWidth(secondImageRef);

    CGFloatsecondHeight =CGImageGetHeight(secondImageRef);

    CGSizemergedSize =CGSizeMake(MAX(firstWidth, secondWidth),MAX(firstHeight, secondHeight));

    UIGraphicsBeginImageContext(mergedSize);

    [firstImagedrawInRect:CGRectMake(0,0, firstWidth, firstHeight)];

    [secondImagedrawInRect:CGRectMake(0,0, secondWidth, secondHeight)];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnimage;

}

你可能感兴趣的:((IOS)合并两个图片)