Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
I have a block of raw pixels of data in the form of RGBA (not preMultipliedAlpha). I want to create a UIImage of that data, retaining the Alpha Channel data.
The best method I have found is to pass it through a CGImage. When I do, the CGImage has no Alpha Channel, so therefore when converted to UIImage I am without one as well.
The question is "How does one make a CGImage that contains an Alpha channel?"
//...
GLubyte *buffer = (GLubyte *) malloc(64 * 64 * 4); // buffer contains unsigned bytes 64 X 64 X 4 bytes per pixel
//...
// make data provider from buffer CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, (64 * 64 * 4), NULL);
// set up for CGImage creation int bitsPerComponent = 8; int bitsPerPixel = 32; int bytesPerRow = 4 * width; CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// test for alpha info = CGImageGetAlphaInfo(imageRef); // Note: Returns “kCGImageAlphaNone”
// make UIImage from CGImage UIImage *newUIImage = [UIImage imageWithCGImage:imageRef];
I have a block of raw pixels of data in the form of RGBA (not preMultipliedAlpha). I want to create a UIImage of that data, retaining the Alpha Channel data.
The best method I have found is to pass it through a CGImage. When I do, the CGImage has no Alpha Channel, so therefore when converted to UIImage I am without one as well.
The question is "How does one make a CGImage that contains an Alpha channel?"
//...
GLubyte *buffer = (GLubyte *) malloc(64 * 64 * 4); // buffer contains unsigned bytes 64 X 64 X 4 bytes per pixel
//...
// make data provider from buffer CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, (64 * 64 * 4), NULL);
// set up for CGImage creation int bitsPerComponent = 8; int bitsPerPixel = 32; int bytesPerRow = 4 * width; CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// test for alpha info = CGImageGetAlphaInfo(imageRef); // Note: Returns kCGImageAlphaNone
// make UIImage from CGImage UIImage *newUIImage = [UIImage imageWithCGImage:imageRef];
Replies
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault
Can be set up to define how Alpha is dealt with:
CGBitmapInfo bitmapInfo =
kCGBitmapByteOrderDefault | kCGImageAlphaLast;
Sets it up for RGBA, non-pre-multiplied.
Hopefully this will help someone else...
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome