⚠️ 如果分割的图片大小不对,可能需要考虑缩放。
请看这里
#pragma mark -分割图片
- (UIImage *)captureOriginalImage:(UIImage *)oImage frame:(CGRect)fra {
CGImageRef ref = CGImageCreateWithImageInRect(oImage.CGImage, fra);
UIImage *i = [UIImage imageWithCGImage:ref];
CGImageRelease(ref);
return i;
}
- (NSMutableArray <UIImage *>*)captureImageArrWithRow:(NSInteger)row Col:(NSInteger)col FromOriginalImage:(UIImage *)oImage{
CGFloat iW = oImage.size.width;
CGFloat iH = oImage.size.height;
CGFloat gW = iW / col;
CGFloat gH = iH / row;
NSMutableArray <UIImage *>*imageArr = [[NSMutableArray alloc]init];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
UIImage *theImage = [self captureOriginalImage:oImage frame:CGRectMake(j*iW/col, i*iH/row, gW, gH)];
[imageArr addObject:theImage];
}
}
return imageArr;
}
效果图:
IMG_0493.jpg
网友评论