动态创建UIImage
UIImage* patternImage = [UIImage FX_imageWitSize:CGSizeMake(100, 100)
generator:^RGBA(size_t x, size_t y){
if( (x%20 < 10) ^ (y%20 < 10) )
return FX_RGBA_Make(200, 200, 200, 255);
else
return FX_RGBA_Make(255, 255, 255, 255);
}];
您可以轻松枚举UIImage中的所有像素
double brightnessSum = 0;
for (UIColor* color in uiImage){
brightnessSum += color.FX_hsba.component.brightness;
}
double averageImageBrightness = brightnessSum / (uiImage.size.width*uiImage.size.height);
或者如果您需要每个像素的X,Y坐标
CGPoint somePoint = CGPointMake(20, 20);
[uiImage FX_enumerateAllPixelsRGBA:^(RGBA rgba, FXPoint point, BOOL *stop) {
double manhattanDistance = ABS(somePoint.x - point.x) + ABS(somePoint.y - point.y);
// do something with distance for point
}];
UIImage* redDecreasedImage = [uiImage FX_imageByMutatePixelsRGBA:^(RGBA rgba, FXPoint point, BOOL *update, BOOL *stop){
if ((point.x % 10 < 5) ^ (point.y%10 < 5)){
rgba.component.r -= 100;
}
return rgba;
}];
pod 'FXColorSpace'