1

我正在使用 Core Image 和 GPUImage 在 iPhone 应用程序中制作一些滤镜。我似乎内存不足并因较大的图像而崩溃。我认为如果我可以将输入图像分成多个部分,这可以解决。

如何在iOS中高效地将图像拆分为多个部分进行图像处理,然后重新组合以将生成的图像作为一个整体输出?

4

1 回答 1

1
-(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);
}
}
于 2012-11-02T11:04:48.463 回答