I am trying to get the prominent colors in an image. Initially I was trying to get the color set as in this post. But my client is not satisfied with it as it returns only the average color set and not the exact color. Hence now Im trying to get the dominant color set by the logic found in this link. But the problem is that the code is in jQuery and JavaScript. Seems its easy to implement in the web as the code is very simple as
myImage = $('#myImage');
dominantColor = getDominantColor(myImage);
paletteArray = createPalette(myImage, 10); // 2nd argument sets # of colors in palette
I surfed how to execute JS in iOS and did in reference to this link and this link and did as below
[_webView loadHTMLString:@"<script src=\"color-thief.js\"></script>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
NSString * imgName = [[NSBundle mainBundle] pathForResource:@"4" ofType:@"jpg"];
// UIImage * img = [UIImage imageNamed:imgName];
int colorCount = 9;
NSString *function1 =[[NSString alloc] initWithFormat: @"createPalette(%@, %d)", imgName, colorCount];
// NSString *function2 = [[NSString alloc] initWithFormat: @"getAverageRGB(%@)", imgName];
NSString *result = [_webView stringByEvaluatingJavaScriptFromString:function1];
NSLog(@"%@ result %@", result, [_webView stringByEvaluatingJavaScriptFromString:funcion1]);
But I couldn't get any result. Its null. What am I missing? Can some one point me what went wrong? Any timely help is appreciated. Thanks in advance.