I have implemented changing the brightness of an image using uislider in iPhone without using openGlImageProcessing. I want to change the brightness of particular area of an image only not the whole image, only particular area of an image should be get brightnessed for example the central area of an image should get brightnessed or particular color from an entire image should get brightnessed. How can we change the brightness of particular portion of an image. Please help me to solve the problem, code is
CGImageRef imageRef = imageView.image.CGImage;
CFDataRef ref = CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
UInt8 * buf = (UInt8 *) CFDataGetBytePtr(ref);
int length = CFDataGetLength(ref);
NSLog(@"%i",val);
float value = val/100;
for(int i=0; i<length; i+=3)
{
Byte tempR = buf[i + 1];
Byte tempG = buf[i + 2];
Byte tempB = buf[i + 3];
int outputRed = value + tempR;
int outputGreen = value + tempG;
int outputBlue = value + tempB;
if (outputRed>255) outputRed=255;
if (outputGreen>255) outputGreen=255;
if (outputBlue>255) outputBlue=255;
if (outputRed<0) outputRed=0;
if (outputGreen<0) outputGreen=0;
if (outputBlue<0) outputBlue=0;
buf[i + 1] = outputRed;
buf[i + 2] = outputGreen;
buf[i + 3] = outputBlue;
}
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
size_t bytesPerRow = CGImageGetBytesPerRow(imageRef);
CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef);
CGContextRef ctx = CGBitmapContextCreate(buf, width, height, bitsPerComponent, bytesPerRow, colorSpace, CGImageGetAlphaInfo(imageRef));
CGImageRef img = CGBitmapContextCreateImage(ctx);
if (value == 0) {
imageView.image = image;
}
else
{
[imageView setImage:[UIImage imageWithCGImage:img]];
}
CFRelease(ref);
CGContextRelease(ctx);
CGImageRelease(img);
After lot of searching i got the answer as