|
|
Convert a PNG into RGBA data at 32 bits per pixel
|
|
|
|
Mac Elite
Join Date: Mar 2001
Location: England
Status:
Offline
|
|
OK, in the app I'm writing I'm passed some PNG data and need to return it as RGBA.
What I've been doing is this:
Code:
NSBitmapImageRep *rep = [[NSBitmapImageRep imageRepWithData:[NSData dataWithBytes:data length:len]] retain];
*width = [rep pixelsWide];
*height = [rep pixelsHigh];
// NSLog(@"%i %i %i", *width, *height, [rep bitsPerPixel]/8);
unsigned char *pixels = malloc(*width * *height * [rep bitsPerPixel]/8);
memcpy(pixels, [rep bitmapData], (*width * *height * [rep bitsPerPixel]/8));
return pixels;
( data contains the PNG and len contains the length).
The problem is, not all these PNGs are 32-bit, and not all contain alpha. I need the bitmap data I return to be in the same format every time... preferably 32-bit RGBA.
Any ideas how I can do this?
Amorya
|
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jan 2002
Status:
Offline
|
|
Create a QuickTime graphics importer for your image, then get a CGImageRef with GraphicsImportCreateCGImage.
Allocate a width * height * sizeof(UInt32) block of memory to hold your 32-bpp RGBA data, then use CGBitmapContextCreate to create a CGContextRef that uses that memory.
Draw your image into the context with CGContextDrawImage, and QT will expand the image data out to the depth of the context.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Mar 2001
Location: England
Status:
Offline
|
|
Cool, thanks. Guess I'm off to read up on Quicktime!
|
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|