有没有办法将亮度应用于uiimages。例如,我有一个UIImageView,里面有一个Uiimage。我想在没有使用GlImageprocessing的情况下在UISlider的帮助下操作亮度。使用iPhone中的滑块进行图像处理
请帮我解决这个问题,请不要向我建议关于GlImage处理。我想不使用GlImageprocessing。
有没有办法将亮度应用于uiimages。例如,我有一个UIImageView,里面有一个Uiimage。我想在没有使用GlImageprocessing的情况下在UISlider的帮助下操作亮度。使用iPhone中的滑块进行图像处理
请帮我解决这个问题,请不要向我建议关于GlImage处理。我想不使用GlImageprocessing。
这里是代码: -
CGImageRef inImage = currentImage.CGImage;
CFDataRef ref = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
UInt8 * buf = (UInt8 *) CFDataGetBytePtr(ref);
int length = CFDataGetLength(ref);
float value2 = (1+slider.value-0.5);
NSLog(@"%i",value);
for(int i=0; i<length; i+=4)
{
int r = i;
int g = i+1;
int b = i+2;
int red = buf[r];
int green = buf[g];
int blue = buf[b];
buf[r] = SAFECOLOR(red*value2);
buf[g] = SAFECOLOR(green*value2);
buf[b] = SAFECOLOR(blue*value2);
}
CGContextRef ctx = CGBitmapContextCreate(buf,
CGImageGetWidth(inImage),
CGImageGetHeight(inImage),
CGImageGetBitsPerComponent(inImage),
CGImageGetBytesPerRow(inImage),
CGImageGetColorSpace(inImage),
CGImageGetAlphaInfo(inImage));
CGImageRef img = CGBitmapContextCreateImage(ctx);
[photoEditView setImage:[UIImage imageWithCGImage:img]];
CFRelease(ref);
CGContextRelease(ctx);
CGImageRelease(img);
在上面定义的: -
#define SAFECOLOR(color) MIN(255,MAX(0,color))
看一看苹果的演示应用程序GLImageProcessing ,它的真快:
开放Gl to UIImage创建
- (UIImage *)glToUIImage {
NSInteger myDataLength = 320 * 480 * 4;
// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, 320, 480, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// gl renders "upside down" so swap top to bottom into new array.
// there's gotta be a better way, but this works.
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
for(int y = 0; y <480; y++)
{
for(int x = 0; x <320 * 4; x++)
{
buffer2[(479 - y) * 320 * 4 + x] = buffer[y * 4 * 320 + x];
}
}
// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(
NULL, buffer2, myDataLength, NULL);
// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * 320;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGImageAlphaNone;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(320, 480, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// then make the uiimage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
//UIImageWriteToSavedPhotosAlbum(myImage,nil,nil,nil);
[[NSUserDefaults standardUserDefaults] setObject:UIImageJPEGRepresentation(myImage,1) forKey:@"image"];
return myImage;
}
哪里是SAFECOLOR定义? – 2012-01-16 13:16:02
有在github上的图像编辑相关的代码我无法找到该链接谷歌可能是你可以找到它具有图像编辑的所有功能的链接 – Leena 2012-01-16 13:18:11