FXColorSpace 0.0.3

FXColorSpace 0.0.3

测试已测试
语言语言 Objective-CObjective C
许可 MIT
发布最后发布2014年12月

未填写维护。



  • 作者:
  • Max Lunin

高级图像像素枚举

动态创建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);
                         }];

输出图像:Pattern created image

您可以轻松枚举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;
                              }];

输出图像:red decreased image

安装

pod 'FXColorSpace'