把开发过程中常用的代码段备份一下,下面的代码内容是关于iphone UIImage 图片处理 灰度 反色 深棕色的代码。
CGImageRef imageRef;
imageRef = anImage.CGImage;
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
size_t bitsPerComponent;
bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
size_t bitsPerPixel;
bitsPerPixel = CGImageGetBitsPerPixel(imageRef);
size_t bytesPerRow;
bytesPerRow = CGImageGetBytesPerRow(imageRef);
CGColorSpaceRef colorSpace;
colorSpace = CGImageGetColorSpace(imageRef);
CGBitmapInfo bitmapInfo;
bitmapInfo = CGImageGetBitmapInfo(imageRef);
bool shouldInterpolate;
shouldInterpolate = CGImageGetShouldInterpolate(imageRef);
CGColorRenderingIntent intent;
intent = CGImageGetRenderingIntent(imageRef);
CGDataProviderRef dataProvider;
dataProvider = CGImageGetDataProvider(imageRef);
CFDataRef data;
data = CGDataProviderCopyData(dataProvider);
NSUInteger x, y;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
UInt8 red,green,blue;
UInt8 brightness;
switch (type) {
break;
break;
break;
default:
break;
}
}
}
CFDataRef effectedData;
effectedData = CFDataCreate(NULL, buffer, CFDataGetLength(data));
CGDataProviderRef effectedDataProvider;
effectedDataProvider = CGDataProviderCreateWithCFData(effectedData);
CGImageRef effectedCgImage;
effectedCgImage = CGImageCreate(
width, height,
bitsPerComponent, bitsPerPixel, bytesPerRow,
colorSpace, bitmapInfo, effectedDataProvider,
NULL, shouldInterpolate, intent);
effectedImage = [[UIImage alloc] initWithCGImage:effectedCgImage];
CGImageRelease(effectedCgImage);
CFRelease(effectedDataProvider);
CFRelease(effectedData);
CFRelease(data);
return effectedImage;
}