0
我已經實現了在不使用openGlImageProcessing的情況下使用iPhone中的uislider更改圖像的亮度。我想改變圖像的特定區域的亮度而不是整個圖像的亮度,只有圖像的特定區域應該變亮,例如圖像的中央區域應該變亮,或者整個圖像的特定顏色應該變亮。我們如何改變圖像特定部分的亮度。請幫我解決這個問題,代碼是在iPhone中使用uislider處理圖像亮度
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);
您是如何來認識改變了圖像的亮度的一部分..越來越之後它從接觸? – vishy 2012-01-17 11:14:37
不只是說中心區域會變亮或者只有特定的顏色應該變亮 – 2012-01-17 11:16:19
難道你不能只調整圖像緩衝區的偏移量並在較小的區域上運行循環嗎? – 2012-01-17 11:22:53