• 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: alpha value from NSBitmapImageRep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: alpha value from NSBitmapImageRep


  • Subject: Re: alpha value from NSBitmapImageRep
  • From: Graham Cox <email@hidden>
  • Date: Tue, 28 Oct 2008 21:33:45 +1100


On 28 Oct 2008, at 8:59 pm, chaitanya pandit wrote:

unsigned char *data = [mImageRep bitmapData] , *pixel;

Now how do i access the pixel information from over here? any idea?


If your bitmap format is ARGB with 8 bits per component, say, then to get the value of A do:

unsigned char alpha = *data;	// get first alpha
data += 4;			// increment pointer to next pixel's alpha

You have to carefully watch the buffer format though. If the bits are packed you'll have to mask off the relevant parts and shift them down to the right position. The raw pixel values have a value range depending on the number of bits per component and may or may not be premultiplied by the alpha value. Also watch the ends of each scanline - the lines are rowBytes long, not necessarily the width of the image.

Basically if you understand how raw pixel buffers are laid out, then you can extract the data you want - you simply get a big chunk of memory laid out accordingly. Note that the format is completely predictable, because you specified it when you created the bitmap in the first place, or, you can ask it for all the various formatting parameters.

hth,


Graham _______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >alpha value from NSBitmapImageRep (From: chaitanya pandit <email@hidden>)

  • Prev by Date: Re: alpha value from NSBitmapImageRep
  • Next by Date: Re: Can we ask iPhone questions yet?
  • Previous by thread: Re: alpha value from NSBitmapImageRep
  • Next by thread: Turning off Auto Complete feature for NSTextField
  • Index(es):
    • Date
    • Thread