Tôi tạo ra một hàm để tách một hình ảnh thành nhiều hình ảnh, nhưng khi tôi đi lấy CGImage của UIImage, các CGImage trả về NULLCGImage của UIImage trả về 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;
}
séc tempArray là null hay không ở cuối – Hector
CGImage không phải là một đối tượng, nó là một cấu trúc C, vì vậy bạn không nên sử dụng một NSLog với% @. – lnafziger
Vấn đề là tôi tạo UIImage bằng IOSurface: D – Otium