我创建了一个用于将图像拆分为多个图像的函数,但是当我获取 UIImage 的 CGImage 时,CGImage 返回 NULL
NSArray* splitImage(UIImage* image,NSUInteger pieces) {
NSLog(@"width: %f, %zu",image.size.width,CGImageGetWidth(image.CGImage));
NSLog(@"%@",image.CGImage);
returns NULL
NSMutableArray* tempArray = [[NSMutableArray alloc]initWithCapacity:pieces];
CGFloat piecesSize = image.size.height/pieces;
for (NSUInteger i = 0; i < pieces; i++) {
// take in account retina displays
CGRect subFrame = CGRectMake(0,i * piecesSize * image.scale ,image.size.width * image.scale,piecesSize * image.scale);
CGImageRef newImage = CGImageCreateWithImageInRect(image.CGImage,subFrame);
UIImage* finalImage =[UIImage imageWithCGImage:newImage];
CGImageRelease(newImage);
[tempArray addObject:finalImage];
}
NSArray* finalArray = [NSArray arrayWithArray:tempArray];
[tempArray release];
return finalArray;
}