Alpha info from NSBitmapImageRep?
Alpha info from NSBitmapImageRep?
- Subject: Alpha info from NSBitmapImageRep?
- From: j o a r <email@hidden>
- Date: Fri, 28 Sep 2001 02:03:40 +0200
Hello,
I'm trying to create a CGImage from an NSBitmapImageRep, this works
fine. My problem is that sometimes I stumble on images of different
types, 24 bit, 32 bit, et.c. and they use alpha in different ways. This
is how it's done, you note that I manage to grab most of the info I need
to create the image directly from the NSBitmapImageRep, leaving little
room for mistakes:
// Create a Core Graphics Image
CGImageRef image = CGImageCreate(
[myBitmap pixelsWide],
[myBitmap pixelsHigh],
[myBitmap bitsPerSample],
[myBitmap bitsPerPixel],
[myBitmap bytesPerRow],
colorSpace,
kCGImageAlphaLast, // <- Here's the problem
provider,
NULL,
0,
kCGRenderingIntentDefault);
For an image grabbed from some standard NSView you get a 32 bit image
with kCGImageAlphaLast - how do I know? I tried the other options and
they didn't work... ;)
You get to choose between:
kCGImageAlphaNone,
kCGImageAlphaPremultipliedLast, /* For example, premultiplied
RGBA */
kCGImageAlphaPremultipliedFirst, /* For example, premultiplied
ARGB */
kCGImageAlphaLast, /* For example, non-premultiplied
RGBA */
kCGImageAlphaFirst, /* For example, non-premultiplied
ARGB */
kCGImageAlphaNoneSkipLast, /* Equivalent to
kCGImageAlphaNone. */
kCGImageAlphaNoneSkipFirst
For the 24 bit images I've tried, I had to use kCGImageAlphaNone to get
it working.
There is probably some much, much, better method I could use, involving
less guesswork, to determine which CGImageAlphaInfo I should use when
creating a CGImage - any pointers?
I'm missing a [myBitmap imageAlpha] method in NSBitmapImageRep...
Regards,
j o a r