Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change the skin color of face from the source image in ios?
    text
    copied!<p>MY code: How to manage RGB value for differet shades of face,and how to apply? this code will change the color of face along with hair,but i want 1.only face to be colored excluding hair.</p> <pre><code> -(void)changeSkinColorValue:(float)value WithImage:(UIImage*)needToModified { CGContextRef ctx; CGImageRef imageRef = needToModified.CGImage; NSUInteger width = CGImageGetWidth(imageRef); NSUInteger height = CGImageGetHeight(imageRef); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); //unsigned char *rawData = malloc(firstImageV.image.size.height * firstImageV.image.size.width * 10); CFMutableDataRef m_DataRef = CFDataCreateMutableCopy(0, 0,CGDataProviderCopyData(CGImageGetDataProvider(firstImageV.image.CGImage))); UInt8 *rawData = (UInt8 *) CFDataGetMutableBytePtr(m_DataRef); int length = CFDataGetLength(m_DataRef); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * firstImageV.image.size.width; NSUInteger bitsPerComponent = 8; CGContextRef context1 = CGBitmapContextCreate(rawData, firstImageV.image.size.width, firstImageV.image.size.height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); CGContextDrawImage(context1, CGRectMake(0, 0, firstImageV.image.size.width, firstImageV.image.size.height), imageRef); NSLog(@"%d::%d",width,height); // for(int ii = 0 ; ii &lt; 250 ; ii+=4) //{ for(int ii = 0 ; ii &lt; length ; ii+=4) { //NSLog(@"Raw data %s",rawData); int R = rawData[ii]; int G = rawData[ii+1]; int B = rawData[ii+2]; // NSLog(@"%d %d %d", R, G, B); //if( ( (R&gt;60)&amp;&amp;(R&lt;237) ) || ((G&gt;10)&amp;&amp;(G&lt;120))||((B&gt;4) &amp;&amp; (B&lt;120))) // if( ( (R&gt;100)&amp;&amp;(R&lt;186) ) || ((G&gt;56)&amp;&amp;(G&lt;130))||((B&gt;30) &amp;&amp; (B&lt;120))) // if( ( (R&gt;188)&amp;&amp;(R&lt;228) ) || ((G&gt;123)&amp;&amp;(G&lt;163))||((B&gt;85) &amp;&amp; (B&lt;125))) // if( ( (R&gt;95)&amp;&amp;(R&lt;260) ) || ((G&gt;40)&amp;&amp;(G&lt;210))||((B&gt;20) &amp;&amp; (B&lt;170))) //new code...... if( ( (R&gt;0)&amp;&amp;(R&lt;260) ) || ((G&gt;0)&amp;&amp;(G&lt;210))||((B&gt;0) &amp;&amp; (B&lt;170))) { rawData[ii+1]=R;//13; rawData[ii+2]=G;//43; rawData[ii+3]=value;//63 } } ctx = CGBitmapContextCreate(rawData, CGImageGetWidth( imageRef ), CGImageGetHeight( imageRef ), 8, CGImageGetBytesPerRow( imageRef ), CGImageGetColorSpace( imageRef ), kCGImageAlphaPremultipliedLast ); imageRef = CGBitmapContextCreateImage(ctx); UIImage* rawImage = [UIImage imageWithCGImage:imageRef]; //UIImageView *ty=[[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 400, 400)]; //ty.image=rawImage; //[self.view addSubview:ty]; [secondImageV setImage:rawImage]; CGContextRelease(context1); CGContextRelease(ctx); free(rawData); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload