• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to determine a single pixels alpha?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: How to determine a single pixels alpha?
      • From: "John C. Randolph" <email@hidden>
References: 
 >How to determine a single pixels alpha? (From: Jesse Grosjean <email@hidden>)

  • Prev by Date: Re: NSScrollView and general IB annoyance
  • Next by Date: Re: Odd stuff with Cocoa-Java
  • Previous by thread: How to determine a single pixels alpha?
  • Next by thread: Re: How to determine a single pixels alpha?
  • Index(es):
    • Date
    • Thread