I'm posting this answer mainly to answer a comment to my question. Here is the solution I used:
- (UIColor*)colorFromImage:(UIImage*)image sampledAtPoint:(CGPoint)p {
// from http://stackoverflow.com/questions/144250/how-to-get-the-rgb-values-for-a-pixel-on-an-image-on-the-iphone
//DLog(@"Image dump call from colorFromImage:sampledAtPoint:");
//[Utilities imageDump:image];
int radius = 3;
CGImageRef cgImage = [image CGImage];
CGDataProviderRef provider = CGImageGetDataProvider(cgImage);
CFDataRef bitmapData = CGDataProviderCopyData(provider);
const UInt8* data = CFDataGetBytePtr(bitmapData);
size_t bytesPerRow = CGImageGetBytesPerRow(cgImage);
size_t width = CGImageGetWidth(cgImage);
size_t height = CGImageGetHeight(cgImage);
CGBitmapInfo info = CGImageGetBitmapInfo(cgImage);
long col = p.x*(width-1);
long row = p.y*(height-1);
long cnt = 0;long redval=0,greenval=0,blueval=0;
for (int rrow = row - radius; rrow < row + radius; rrow++) {
for (int ccol = col - radius; ccol < col + radius; ccol++) {
if ((rrow >= 0) && (ccol >= 0)) {
if ((rrow < height) && (ccol < width)) {
const UInt8* pixel = data + rrow*bytesPerRow+ccol*4;
int tempred,tempgreen,tempblue,tempalpha;
if (info & kCGBitmapByteOrder32Little) {
tempred = pixel[2];
tempgreen = pixel[1];
tempblue = pixel[0];
tempalpha = pixel[3];
} else {
tempred = pixel[0];
tempgreen = pixel[1];
tempblue = pixel[2];
tempalpha = pixel[3];
}
//DLog(@"%d %d %d %d",tempred,tempgreen,tempblue,tempalpha);
if (tempalpha==255) {
redval += tempred;
greenval += tempgreen;
blueval += tempblue;
cnt++;
}
}
}
}
}
UIColor *returnColor = [UIColor colorWithRed:1.0f*redval/(cnt*255) green:1.0f*greenval/(cnt*255) blue:1.0f*blueval/(cnt*255) alpha:1.0];
CFRelease(bitmapData);//take care of memory leak
return returnColor;
}
I seem to recall that it wasn't a complete solution but was sufficient for my own purposes.