Hi
In my application I m using following way to get red pixel in a image
//
// PixelsAccessAppDelegate.h
// PixelsAccess
//
// Created by Fortune1 on 14/04/10.
// Copyright MyCompanyName 2010. All rights reserved.
//
import
@class clsPixelAccess;
NSUInteger numberOfRedPixels;
NSUInteger numberOfRedPixels1;
NSUInteger numberOfRedPixels2;
NSUInteger numberOfRedPixels3;
NSUInteger numberOfRedPixels4;
NSUInteger numberOfRedPixels5;
NSUInteger numberOfRedPixels6;
NSUInteger numberOfRedPixels7;
NSUInteger numberOfRedPixels8;
NSUInteger numberOfRedPixels9;
NSUInteger numberOfRedPixels10;
NSUInteger numberOfRedPixels11;
NSUInteger numberOfRedPixels12;
NSUInteger numberOfRedPixels13;
NSUInteger numberOfRedPixels14;
NSUInteger numberOfRedPixels15;
NSUInteger numberOfRedPixels16;
NSUInteger numberOfRedPixels17;
NSUInteger numberOfRedPixels18;
NSUInteger numberOfRedPixels19;
NSUInteger numberOfRedPixels20;
NSUInteger numberOfRedPixels21;
NSUInteger numberOfRedPixels22;
NSUInteger numberOfRedPixels23;
NSUInteger numberOfRedPixels24;
NSUInteger numberOfRedPixels25;
NSUInteger numberOfRedPixels26;
NSUInteger numberOfRedPixels27;
NSUInteger numberOfRedPixels28;
NSUInteger numberOfRedPixels29;
NSUInteger numberOfRedPixels30;
NSUInteger numberOfRedPixels31;
@interface PixelsAccessAppDelegate : NSObject {
UIWindow *window;
clsPixelAccess *obj;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
-(IBAction)processImage:(id)sender;
@end
////////////////////
//
// PixelsAccessAppDelegate.m
// PixelsAccess
//
// Created by Fortune1 on 14/04/10.
// Copyright MyCompanyName 2010. All rights reserved.
//
import "PixelsAccessAppDelegate.h"
import "clsPixelAccess.h"
@implementation PixelsAccessAppDelegate
@synthesize window;
(IBAction)processImage:(id)sender
{
NSUInteger retVal;
obj = [[clsPixelAccess alloc] init];
NSInteger imageSend =[obj processImage1:[UIImage imageNamed:@"s.jpg"]];
NSInteger iamgeCall =[obj getPixelData:retVal];
NSUInteger *numberOfRedPixels = retVal;
//lblPixelCount.text = [NSString stringWithFormat: @"There are %d red pixels in the image", numberOfRedPixels];
}
(void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
}
(void)dealloc {
[window release];
[super dealloc];
}
@end
///////////////
//
// clsPixelsAccess.h
// PixelsAccess
//
// Created by Fortune1 on 14/04/10.
// Copyright 2010 MyCompanyName. All rights reserved.
//
import
@interface clsPixelAccess : NSObject {
}
-(NSInteger) processImage1: (UIImage*) image;
-(NSInteger)getPixelData:(NSUInteger *)pixelCount;
@end
/////////
//
// clsPixelsAccess.m
// PixelsAccess
//
// Created by Fortune1 on 14/04/10.
// Copyright 2010 MyCompanyName. All rights reserved.
//
import "clsPixelAccess.h"
import "PixelsAccessAppDelegate.h"
@implementation clsPixelAccess
struct pixel
{
//unsigned char r, g, b,a;
Byte r, g, b, a;
int count;
};
-(NSInteger)getPixelData:(NSUInteger *)pixelCount
{
*pixelCount =numberOfRedPixels;
return 1;
}
// Process the image and return the number of pure red pixels in it.
(NSInteger) processImage1: (UIImage*) image
{
// Allocate a buffer big enough to hold all the pixels
struct pixel* pixels = (struct pixel*) calloc(1, image.size.width * image.size.height * sizeof(struct pixel));
if (pixels != nil)
{
// Create a new bitmap
CGContextRef context = CGBitmapContextCreate(
(void*) pixels,
image.size.width,
image.size.height,
8,
image.size.width * 4,
CGImageGetColorSpace(image.CGImage),
kCGImageAlphaPremultipliedLast
);
//NSLog(@"1=%d, 2=%d, 3=%d", CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image),CGImageGetBytesPerRow(image));
if (context != NULL)
{
// Draw the image in the bitmap
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, image.size.width, image.size.height), image.CGImage);
NSUInteger numberOfPixels = image.size.width * image.size.height;
NSMutableArray *numberOfPixelsArray = [[[NSMutableArray alloc] initWithCapacity:numberOfPixelsArray] autorelease];
NSLog( @"Pixel data %d", numberOfPixelsArray);
/*
NSMatrix *newMatrix = [[NSMatrix alloc]
initWithFrame:NSMakeRect(138.0f, 85.0f, 0.0f, 0.0f)
mode:NSRadioModeMatrix
prototype:prototypeButtonCell
numberOfRows:
numberOfColumns:];
*/
while (numberOfPixels > 0)
{
if (pixels->r > 0 && pixels->r <= 7)
{
numberOfRedPixels++;
}
NSLog( @"Red pixel data %d",numberOfRedPixels);
if (pixels->r >= 8 && pixels->r <= 15)
{
numberOfRedPixels1++;
}
NSLog( @"Red pixel data1 %d",numberOfRedPixels1);
if (pixels->r >= 16 && pixels->r <=23 )
{
numberOfRedPixels2++;
}
NSLog( @"Red pixel data2 %d",numberOfRedPixels2);
if (pixels->r >= 24 && pixels->r <=31 )
{
numberOfRedPixels3++;
}
NSLog( @"Red pixel data3 %d",numberOfRedPixels3);
if (pixels->r >= 32 && pixels->r <= 39)
{
numberOfRedPixels4++;
}
NSLog( @"Red pixel data4 %d",numberOfRedPixels4);
if (pixels->r >= 40 && pixels->r <= 47)
{
numberOfRedPixels5++;
}
NSLog( @"Red pixel data5 %d",numberOfRedPixels5);
if (pixels->r >= 48 && pixels->r <= 55)
{
numberOfRedPixels6++;
}
NSLog( @"Red pixel data6 %d",numberOfRedPixels6);
if(pixels->r >= 56 && pixels->r <= 63)
{
numberOfRedPixels7++;
}
NSLog( @"Red pixel data7 %d",numberOfRedPixels7);
if (pixels->r >= 64 && pixels->r <= 71)
{
numberOfRedPixels8++;
}
NSLog( @"Red pixel data8 %d",numberOfRedPixels8);
if (pixels->r >= 72 && pixels->r <= 79)
{
numberOfRedPixels9++;
}
NSLog( @"Red pixel data9 %d",numberOfRedPixels9);
if (pixels->r >= 80 && pixels->r <= 87)
{
numberOfRedPixels10++;
}
NSLog( @"Red pixel data10 %d",numberOfRedPixels10);
if (pixels->r >= 88 && pixels->r <= 95)
{
numberOfRedPixels11++;
}
NSLog( @"Red pixel data11 %d",numberOfRedPixels11);
if (pixels->r >= 96 && pixels->r <= 103)
{
numberOfRedPixels12++;
}
NSLog( @"Red pixel data12 %d",numberOfRedPixels12);
if (pixels->r >= 104 && pixels->r <= 111)
{
numberOfRedPixels13++;
}
NSLog( @"Red pixel data13 %d",numberOfRedPixels13);
if (pixels->r >= 112 && pixels->r <= 119)
{
numberOfRedPixels14++;
}
NSLog( @"Red pixel data14 %d",numberOfRedPixels14);
if (pixels->r >= 120 && pixels->r <= 127)
{
numberOfRedPixels15++;
}
NSLog( @"Red pixel data15 %d",numberOfRedPixels15);
if (pixels->r > 128 && pixels->r <= 135)
{
numberOfRedPixels16++;
}
NSLog( @"Red pixel data16 %d",numberOfRedPixels16);
if (pixels->r >= 136 && pixels->r <= 143)
{
numberOfRedPixels17++;
}
NSLog( @"Red pixel data17 %d",numberOfRedPixels17);
if (pixels->r >= 144 && pixels->r <=151)
{
numberOfRedPixels18++;
}
NSLog( @"Red pixel data18 %d",numberOfRedPixels18);
if (pixels->r >= 152 && pixels->r <=159 )
{
numberOfRedPixels19++;
}
NSLog( @"Red pixel data19 %d",numberOfRedPixels19);
if (pixels->r >= 160 && pixels->r <= 167)
{
numberOfRedPixels20++;
}
NSLog( @"Red pixel data20 %d",numberOfRedPixels20);
if (pixels->r >= 168 && pixels->r <= 175)
{
numberOfRedPixels21++;
}
NSLog( @"Red pixel data21 %d",numberOfRedPixels21);
if (pixels->r >= 176 && pixels->r <= 199)
{
numberOfRedPixels22++;
}
NSLog( @"Red pixel data22 %d",numberOfRedPixels22);
if(pixels->r >= 184 && pixels->r <= 191)
{
numberOfRedPixels23++;
}
NSLog( @"Red pixel data23 %d",numberOfRedPixels23);
if (pixels->r >= 192 && pixels->r <= 199)
{
numberOfRedPixels24++;
}
NSLog( @"Red pixel data24 %d",numberOfRedPixels24);
if (pixels->r >= 200 && pixels->r <= 207)
{
numberOfRedPixels25++;
}
NSLog( @"Red pixel data25 %d",numberOfRedPixels25);
if (pixels->r >= 208 && pixels->r <= 215)
{
numberOfRedPixels26++;
}
NSLog( @"Red pixel data26 %d",numberOfRedPixels26);
if (pixels->r >= 216 && pixels->r <= 223)
{
numberOfRedPixels27++;
}
NSLog( @"Red pixel data27 %d",numberOfRedPixels27);
if (pixels->r >= 224 && pixels->r <= 231)
{
numberOfRedPixels28++;
}
NSLog( @"Red pixel data28 %d",numberOfRedPixels28);
if (pixels->r >= 232 && pixels->r <= 239)
{
numberOfRedPixels29++;
}
NSLog( @"Red pixel data29 %d",numberOfRedPixels29);
if (pixels->r >= 240 && pixels->r <= 247)
{
numberOfRedPixels30++;
}
NSLog( @"Red pixel data30 %d",numberOfRedPixels30);
if (pixels->r >= 248)
{
numberOfRedPixels31++;
}
NSLog( @"Red pixel data31 %d",numberOfRedPixels31);
pixels++;
numberOfPixels--;
}
CGContextRelease(context);
}
free(pixels);
}
return 1;
}
@end
My problem is I want skin Tone Pixel how it could be possible
Please help me out.
Thanks in Advance