• 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
Reading RGBA pixel values from image on disk
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Reading RGBA pixel values from image on disk
      • From: Seth Willits <email@hidden>
    • Re: Reading RGBA pixel values from image on disk
      • From: Quincey Morris <email@hidden>
  • Prev by Date: [ANN] AppKiDo 0.986sp4, Xcode 4, GitHub
  • Next by Date: Testing apps on Mac OS X 10.5
  • Previous by thread: [ANN] AppKiDo 0.986sp4, Xcode 4, GitHub
  • Next by thread: Re: Reading RGBA pixel values from image on disk
  • Index(es):
    • Date
    • Thread