1. gairp's Avatar
    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;
    }
    this is equalPixels function
    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 AM
  2. gairp's Avatar
    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;
    }
    this is equalPixels function
    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 AM
LINK TO POST COPIED TO CLIPBOARD