How do I randomly generate number to change contrast of a UIImage?

242 Views Asked by At

I need to randomly generate the contrast of a UIImage. How do i do so? Also if you could tell me how to do the same for hue, brightness, sharpness, saturation, ect.

2

There are 2 best solutions below

1
On

you can generate a random number this way:

int x = arc4random() % 1000;

that generates a random number between 0 and 999. a float you can generate with:

#define ARC4RANDOM_MAX      0x100000000

double myValue = floorf(((double)arc4random() / ARC4RANDOM_MAX) * 10.0f);
1
On

You can use this image filtering category

https://github.com/esilverberg/ios-image-filters

and just go:

[myImage brightness:arc4random() % 256 / 255]