• 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
How to determine a single pixels alpha?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to determine a single pixels alpha?


  • Subject: How to determine a single pixels alpha?
  • From: Jesse Grosjean <email@hidden>
  • Date: Sun, 30 Sep 2001 17:36:41 -0400

I'm trying to figure out the best way to determine if a NSImage is transparent at a given point, and wondering what the best way to go about it would be. I've gotten to the point of grabbing a NSBitmapImageRep from the NSImage but can't seem to figure out how to go through the bitmapData correctly. Bellow is what i have now (doesn't work very well). Would love to hear how someone else would go about doing this.

- (BOOL)pick:(NSPoint)aPoint using:(NSBitmapImageRep *)aBitmapImageRep {
if (![aBitmapImageRep hasAlpha]) {
return YES;
} else {
int i,j;
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++;
}
}

if (alpha == 0) {
return NO;
}
}
return YES;
}

Thanks,
Jesse


  • Follow-Ups:
    • Re: How to determine a single pixels alpha?
      • From: Peter Ammon <email@hidden>
    • Re: How to determine a single pixels alpha?
      • From: Brian Hook <email@hidden>
  • Prev by Date: Re: [Carbon] Using Speech in Cocoa
  • Next by Date: Re: Does cocoa just leak?
  • Previous by thread: Re: NSScrollView and general IB annoyance
  • Next by thread: Re: How to determine a single pixels alpha?
  • Index(es):
    • Date
    • Thread