Reading RGBA pixel values from image on disk
Reading RGBA pixel values from image on disk
- Subject: Reading RGBA pixel values from image on disk
- From: Leonardo <email@hidden>
- Date: Thu, 10 Mar 2011 16:18:40 +0100
- Thread-topic: Reading RGBA pixel values from image on disk
Hi,
I have to read all the RGBA values of every pixel of an image on the disk,
as tif, png, jpg I read the imageRep with imageRepWithContentsOfFile and
get the RGBA values with "colorAtX: y:" It works quite well with png images
with "non alpha premultiplied" bitmap format. In this case I get a
bitsPerPixel = 32.
But if I save the same image with Photoshop as TIF, I get an "alpha
premultiplied" bitmap format and a bitsPerPixel = 24. But worst of all, all
the alpha values are 1.0, while some of them is for sure 0.5. So I can't
even calculate the original non multiplied RGB values.
My question is: how can I get the true original RGBA pixels values of any
image? Actually I do:
imageRep = [NSBitmapImageRep imageRepWithContentsOfFile:filePath];
texWidth = [imageRep pixelsWide];
texHeight = [imageRep pixelsHigh];
for(y = 0; y < texHeight; y++){
for(x = 0; x < texWidth; x++){
NSColor *pixelColor = [imageRep colorAtX:x y:y];
NSColor *rgbColor = [pixelColor colorUsingColorSpace:
[NSColorSpace deviceRGBColorSpace]];
[rgbColor getRed:
&rgba[0] green:&rgba[1] blue:&rgba[2] alpha:&rgba[3]];
}
}
Regards
-- Leonardo
_______________________________________________
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