Re: Setting a NSPitmapImageRep which NSImages draw to
Re: Setting a NSPitmapImageRep which NSImages draw to
- Subject: Re: Setting a NSPitmapImageRep which NSImages draw to
- From: Ian Henderson <email@hidden>
- Date: Fri, 18 Jun 2004 10:49:18 -0400
On Fri, 18 Jun 2004 14:43:48 +0200, Henrik Dalgaard
<email@hidden> wrote:
>
>
Den Jun 18, 2004, kl. 1:36 AM, skrev Andrew Platzer:
>
>
> On Jun 17, 2004, at 10:09 AM, Henrik Dalgaard wrote:
>
>> I can not figure out how to pull pixels out of a NSImage!
>
>
>
> [image lockFocus];
>
> NSBitmapImageRep* rep = [[NSBitmapImageRep alloc]
>
> initWithFocusedViewRect:NSMakeRect(0, 0, [image size].width, [image
>
> size].height)];
>
> [image unlockFocus];
>
>
>
> That will return an NSBitmapImageRep that is 8 bits/sample, 3 or 4
>
> samples/pixel depending on whether the image has alpha in RGBA
>
> premultiplied format. You can then read the individual pixels by using
>
> the following:
>
>
>
> unsigned char* pixel = [rep bitmapData] + y * [rep bytesPerRow] + x *
>
> [rep samplesPerPixel];
>
> unsigned char r = pixel[0];
>
> unsigned char g = pixel[1];
>
> unsigned char b = pixel[2];
>
> unsigned char a = pixel[3]; // if spp == 4 or hasAlpha == YES
>
>
Thanks this is good information, which I could not find in the
>
documentation. It seems that I only have to be concerned with the
>
optional alpha channel. I is nice to avoid making support for all the
>
pixelformats NSBitmapImageRep supports.
>
I suppose (but check anyways) that i won't get compressed data, planar
>
data or CMYK pixels.
>
>
I have tried to force the image to get an alpha channel by sending
>
setAlpha:YES to its cached image rep, but that did not work. I don't
>
really need the alpha channel, but the vImage framework requires alpha
>
when dealing with chunky pixels. I was looking for a way to avoid
>
manually inserting the alpha bytes. Switching to planar pixels in my
>
code will probably be my best option. The alpha is also the first
>
component in vImage.
>
>
Thanks,
>
-Hernik
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
>
>
What about locking the NSImage and using NSReadPixel(), with an
argument of the point where you want to get the color?
- Ian
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.