如何在iOS中将白色皮肤脸变为深色皮肤? [英] How change the white skin face to dark skin face in iOS?

查看:182
本文介绍了如何在iOS中将白色皮肤脸变为深色皮肤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将白色皮肤脸变为深色皮肤脸...
例如美国白脸到非洲脸(即色调)......

I need to change the white skin face to dark skin face... For example American white face to African face(i.e color tone)...

我通过数字色度计选择像素的颜色值,它为深色皮肤提供RGB值[红色= 101,绿色= 63和蓝色= 43],对于白色皮肤,它给出RGB值为[红色= 253] ,green = 210和blue = 176] ...

I pick the color value of the pixel by digital color meter it gives the RGB value[red=101,green=63 and blue=43] for dark skin and for white skin it gives the RGB value as [red=253,green=210 and blue=176]...

然后我在我的代码中设置该值会得到错误的结果......

Then i am setting that value in my code it gives the false result...

这是我的代码......

Here is my code...

   -(UIImage*)customBlackFilterOriginal
{
    CGImageRef imgSource=self.duplicateImage.image.CGImage;
    CFDataRef m_DataRef1 = CGDataProviderCopyData(CGImageGetDataProvider(imgSource)); 
    UInt8 *dataOriginal=(UInt8 *)CFDataGetBytePtr(m_DataRef1);
    double lengthSource=CFDataGetLength(m_DataRef1);
    NSLog(@"length::%f",lengthSource);
    int redPixel;
    int greenPixel;
    int bluePixel;

    for(int index=0;index<lengthSource;index+=4)
    {

        dataOriginal[index]=dataOriginal[index];
        dataOriginal[index+1]= 101;
        dataOriginal[index+2]= 63;
        dataOriginal[index+3]=43;      

    } 

    NSUInteger width =CGImageGetWidth(imgSource);
    size_t height=CGImageGetHeight(imgSource);
    size_t bitsPerComponent=CGImageGetBitsPerComponent(imgSource);
    size_t bitsPerPixel=CGImageGetBitsPerPixel(imgSource);
    size_t bytesPerRow=CGImageGetBytesPerRow(imgSource);

    NSLog(@"the w:%u H:%lu",width,height);

    CGColorSpaceRef colorspace=CGImageGetColorSpace(imgSource);
    CGBitmapInfo bitmapInfo=CGImageGetBitmapInfo(imgSource);
    CFDataRef newData=CFDataCreate(NULL,dataOriginal,lengthSource);
    CGDataProviderRef provider=CGDataProviderCreateWithCFData(newData);
    CGImageRef newImg=CGImageCreate(width,height,bitsPerComponent,bitsPerPixel,bytesPerRow,colorspace,bitmapInfo,provider,NULL,true,kCGRenderingIntentDefault);

    return [UIImage imageWithCGImage:newImg];

}

请分享有关上述变色的任何想法... 。
我在代码中犯了什么错误?..

please share any idea about the above color changing.... what mistake i did in the code?..

推荐答案

我不是一个iPhone程序员,所以除了一些我不能测试任何东西你的代码中的东西很奇怪:

I am not an IPhone programmer so I can't test anything but some things are odd in your code:

像素大小
在阅读你的数据时,你似乎假设你有一张32位的ARGB图片,你确认是这样吗?

Pixel size When reading your data, you seem to assume you have a 32bits ARGB picture, did you validate it's the case?

CFDataGetBytePtr
根据文档,它返回读取-only指向CFData对象的字节。,你确定你不是在寻找 CFDataGetBytes 哪个拷贝CFData对象的字节内容到外部缓冲区。在这种情况下,您必须分配缓冲区以包含 width * height * bpp 。一旦你有这个副本,无论如何你都可以操作它来创建新图片。

CFDataGetBytePtr According to the docs, it Returns a read-only pointer to the bytes of a CFData object., are you sure you're not looking for CFDataGetBytes which Copies the byte contents of a CFData object to an external buffer. In which case you'll have to allocate your buffer to contain width * height * bpp. Once you have this copy, you can manipulate it anyway you want to create the new picture.

像素选择
根据你的问题,我似乎明白你想要将肤色从白色变为黑色。您当前的代码会迭代每个像素以更改其颜色。您应该评估像素颜色与您要查找的颜色之间的距离,如果它低于某个阈值则处理它。在 HSV 中执行操作可能比处理RGB颜色更容易。

Pixel Selection According to your question, I seem to understand that you want to change skin color from White to Black. Your current code iterates over every pixel to change its color. You should evaluate the "distance" between the pixel color and what you're looking for, and if it's below a certain threshold process it. It might be easier to perform the operation in HSV than by dealing with RGB colors.

这篇关于如何在iOS中将白色皮肤脸变为深色皮肤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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