我正在使用Core Image和GPUImage在iPhone应用程序中进行一些过滤。我似乎内存不足,并且崩溃了大图。我认为如果我可以将输入图像分成多个部分,就可以解决。
如何有效地将图像分成多个部分进行图像处理,然后重新组合以在iOS中整体输出结果图像?
最佳答案
-(void)getMultipleImages:(UIImage*)image AndNumberOfPart:(NSInteger)matrixSize{
CGSize size = image.size;
//for storing rect values of puzzle boxess
NSMutableArray *puzzleRectArr = [[NSMutableArray alloc]init];
NSMutableArray *puzzleCroppedObj = [[NSMutableArray alloc]init];
int widthD = size.width;
int heightD = size.height;
float boxWidth = widthD/matrixSize;
float boxHeight = heightD/matrixSize;
for (int i = 0; i < matrixSize*matrixSize; i++) {
int x = (widthD/matrixSize)/2 + (widthD/matrixSize) *(i%matrixSize)-boxWidth/2;
int y = (heightD/matrixSize)/2 + (heightD/matrixSize)* (i/matrixSize)-boxHeight/2;
CGRect rect = CGRectMake(x, y, boxWidth, boxHeight);
[puzzleRectArr addObject:[NSValue valueWithCGRect:rect]];
CGImageRef imageRef = CGImageCreateWithImageInRect([self.imgActual CGImage], rect);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
//----------------------------------------------------------------------
//here You can find the part image
[puzzleCroppedObj addObject:croppedImage];
//----------------------------------------------------------------------
CGImageRelease(imageRef);
}
}