我創建了一個函數的圖像分割成多個圖像,但是當我拿拿的UIImage的CGImage,在CGImage返回NULL的UIImage的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;
}
檢查tempArray爲空或不是在最後 – Hector 2012-04-05 04:22:25
CGImage是不是一個對象,它是一個C結構,所以你不應該使用的NSLog與%@。 – lnafziger 2012-04-05 04:24:37
問題是我用IOSurface創建了UIImage:D – Otium 2012-04-05 04:28:46