이미지에서 눈에 띄는 색상을 얻으려고합니다. 처음에는 this post처럼 색상을 설정하려고했습니다. 하지만 클라이언트는 정확한 색상이 아닌 평균 색상 세트 만 반환하기 때문에 만족하지 않습니다. 그러므로 이제는 this link.에있는 논리에 따라 지배적 인 색을 설정하려고합니다.하지만 문제는 jQuery와 JavaScript에 문제가 있다는 것입니다. 코드가 나는 아이폰 OS에 JS를 실행하는 방법 서핑과 this link 및 this link를 참조했고, 다음과 같이iOS 앱에 jquery-javascript 프로젝트 통합
[_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]);
했다 매우 간단
myImage = $('#myImage');
dominantColor = getDominantColor(myImage);
paletteArray = createPalette(myImage, 10); // 2nd argument sets # of colors in palette
로 그대로 웹에서 구현하기 쉬운 것 같습니다 그러나 나는 어떤 결과도 얻을 수 없었다. 그것의 null. 내가 뭘 놓치고 있니? 어떤 점이 잘못되었다고 지적 할 수 있습니까? 시의 적절한 도움을 주시면 감사하겠습니다. 미리 감사드립니다.