Re: alpha value from NSBitmapImageRep
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