使用iphone中的滑块进行图像处理 [英] image manipulation using slider in iphone

查看:92
本文介绍了使用iphone中的滑块进行图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将亮度应用于uiimages。例如,我有一个UIImageview,里面我有一个uiimage。我希望在不使用GlImageprocessing的情况下借助UISlider来操纵它的亮度。

Is there a way to apply brightness to uiimages. For example I have a UIImageview and inside that i have a uiimage. I want to manipulate its brightness with a help of UISlider without using GlImageprocessing.

请帮我解决这个问题,请不要向我推荐GlImageprocessing。我想在不使用GlImageprocessing的情况下这样做。

Please help me to solve this problem and please don't suggest me about GlImageprocessing. I want to do it without using 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))

这篇关于使用iphone中的滑块进行图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆