Time to upgrade! Get an iPhone 12 mini + Unlimited Data for $60/mo
- i want to get pixel color from UIImage, compare if is black color, and i have such funtion for duing this..
i need only my color at (GamePlayer.playerFrame.origin.x,GamePlayer.player Frame.origin.y) pixel
and how can i get it?
Code:-(BOOL) playerColidesWall { BOOL result = NO; struct pixel* pixels = (struct pixel*) calloc(1, self.bounds.size.width * self.bounds.size.height * sizeof(struct pixel)); if (pixels != nil) { // Create a new bitmap CGContextRef context = CGBitmapContextCreate( (void*) pixels, self.bounds.size.width, self.bounds.size.height, 8, self.bounds.size.width * 4, CGImageGetColorSpace(currentLevelInfo.levelImage.CGImage), kCGImageAlphaPremultipliedLast ); if (context != NULL) { CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, self.bounds.size.width, self.bounds.size.height), currentLevelInfo.levelImage.CGImage); struct pixel black = {0,0,0,0}; if(![self equalPixels:&pixels[(int)(GamePlayer.playerFrame.origin.x*GamePlayer.playerFrame.origin.y)]:&black]) { result = YES; } CGContextRelease(context); } free(pixels); } return result; }
Code:-(BOOL) equalPixels:(struct pixel*) pix1 :(struct pixel*) pix2 { NSLog(@"pixelcolor(%d,%d,%d)",pix1->r,pix1->b,pix1->g); return (pix1->r==pix2->r && pix1->b==pix2->b && pix1->g==pix2->g); } //and this is pixles struct struct pixel { unsigned char r, g, b, a; };
05-23-2011 04:24 AMLike 0 - i want to get pixel color from UIImage, compare if is black color, and i have such funtion for duing this..
i need only my color at (GamePlayer.playerFrame.origin.x,GamePlayer.player Frame.origin.y) pixel
and how can i get it?
Code:-(BOOL) playerColidesWall { BOOL result = NO; struct pixel* pixels = (struct pixel*) calloc(1, self.bounds.size.width * self.bounds.size.height * sizeof(struct pixel)); if (pixels != nil) { // Create a new bitmap CGContextRef context = CGBitmapContextCreate( (void*) pixels, self.bounds.size.width, self.bounds.size.height, 8, self.bounds.size.width * 4, CGImageGetColorSpace(currentLevelInfo.levelImage.CGImage), kCGImageAlphaPremultipliedLast ); if (context != NULL) { CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, self.bounds.size.width, self.bounds.size.height), currentLevelInfo.levelImage.CGImage); struct pixel black = {0,0,0,0}; if(![self equalPixels:&pixels[(int)(GamePlayer.playerFrame.origin.x*GamePlayer.playerFrame.origin.y)]:&black]) { result = YES; } CGContextRelease(context); } free(pixels); } return result; }
Code:-(BOOL) equalPixels:(struct pixel*) pix1 :(struct pixel*) pix2 { NSLog(@"pixelcolor(%d,%d,%d)",pix1->r,pix1->b,pix1->g); return (pix1->r==pix2->r && pix1->b==pix2->b && pix1->g==pix2->g); } //and this is pixles struct struct pixel { unsigned char r, g, b, a; };
05-23-2011 04:27 AMLike 0
- Forum
- Developers
- The Developer's Lounge
Can't getting pixels from UIImage
LINK TO POST COPIED TO CLIPBOARD