Re: How to determine a single pixels alpha?
Re: How to determine a single pixels alpha?
- Subject: Re: How to determine a single pixels alpha?
- From: Brian Hook <email@hidden>
- Date: Sun, 30 Sep 2001 15:30:29 -0700
At 05:36 PM 9/30/01 -0400, Jesse Grosjean wrote:
unsigned char* pixels = [aBitmapImageRep bitmapData];
int alpha;
// i'm trying to get to the pixel specified by aPoint. I'm sure i
should be able to index
// into this with an array somehow "pixels[aPoint.x][aPoint.y]"
but can't figure out how
// to do that. In any case I'm pretty sure this loop is where i'm
doing things wrong, the pick
// works correctly sometimes, but other returns the wrong answer.
for(i= 0; i <= aPoint.x; i++) {
for (j = 0; j <= aPoint.y; j++) {
pixels++; // red
pixels++; // blue
pixels++; // green
alpha = *pixels++;
}
}
I don't know the ordering of pixels in BSBitmapImageRep off the top of my
head, but you seem to be stepping through it in x-major order, so assuming
that, you should be able to fetch the pixel you want directly just doing:
unsigned char *pPixel = &pixels[ aPoint.x * 4 + aPoint.y * 4 * imageWidth ];
Where "imageWidth" is the width of the bitmap data in pixels.
Then it's just a matter of:
if ( pPixel[ 3 ] == 0 )
return NO;
return YES;
Brian