I have a view with 50 im开发者_StackOverflow中文版ages. Images may overlap. I want (for example) select image number 33 and find pixel color. How can i do this ? PS i use glReadPixels.
Unless you want to kill time applying the image as a texture first, you wouldn't use glReadPixels. You can do this directly from the UIImage instead:
void pixelExamine( UIImage *image )
{
CGImageRef colorImage = image.CGImage;
int width = CGImageGetWidth(colorImage);
int height = CGImageGetHeight(colorImage);
uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), colorImage);
int x;
int y;
uint8_t *rgbaPixel;
for( y = 0; y < height; y++)
{
rgbaPixel = (uint8_t *) &pixels[y * width];
for( x = 0; x < width; x++, rgbaPixel+=4)
{
// rgbaPixel[0] = ALPHA 0..255
// rgbaPixel[3] = RED 0..255
// rgbaPixel[2] = GREEN 0..255
// rgbaPixel[1] = BLUE 0..255
}
}
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
free(pixels);
}
精彩评论