1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| }
/// 多张图片拼接成长图 /// - Parameters: /// - images: 需要拼接的图片 /// - width: 目标图片的宽度 - (UIImage *)stitchImageWithImages:(NSArray<UIImage *> *)images width:(CGFloat)width { CGFloat height = 0; NSMutableArray *newImages = [NSMutableArray array]; for (UIImage *image in images) { UIImage *newImage = [self fixImageSizeWithImage:image width:width]; [newImages addObject:newImage]; height += newImage.size.height; } CGSize size = CGSizeMake(width, height); UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale); CGFloat Y = 0; for (int i = 0; i < newImages.count; i++) { UIImage *image = newImages[i]; if (i > 0) { UIImage *proImage = newImages[i - 1]; Y = Y + proImage.size.height; } [image drawInRect:CGRectMake(0,Y, width, image.size.height)]; } UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; }
|