Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to determine a single pixels alpha?



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


References: 
 >How to determine a single pixels alpha? (From: Jesse Grosjean <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.