It looks like you're new here. If you want to get involved, click one of these buttons!
NSInteger myDataLength = 320 * 480 * 4;
// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, 320, 480, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// gl renders \"upside down\" so swap top to bottom into new array.
// there's gotta be a better way, but this works.
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
for(int y = 0; y < 480; y++)
{
for(int x = 0; x <320 * 4; x++) {
buffer2[(479 - y) * 320 * 4 + x] = buffer[y * 4 * 320 + x];
}
}
// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL);
// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * 320;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(320, 480, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// then make the uiimage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
UIImageWriteToSavedPhotosAlbum(myImage, self, nil, nil);
Replies
When are you calling it?
Visit Mr Jack Games for my blog and more
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome:confused:
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomefor this:
before performing this you need to set the opaque attribute of the layer to NO...
;)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeDo you have imagery on screen that is not going through OpenGLES?
Do you get any warnings during compilation?
Visit Mr Jack Games for my blog and more
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeVisit Mr Jack Games for my blog and more
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThe only thing to do at once is to free memory.
These lines are pretty straight forward:
But CGDataProviderRef need to be created another way to invoke release callback function and free buffer used as data provider:
Last parameter is a callback function which is invoked when resources are no longer needed. Something like this:
void ProviderReleaseData ( void *info, const void *data, size_t size ) {free(info);
}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI am doing some HUE filtering using OpenGLES and when I save to an UIImage it is successful and looks good in the preview thumbnail in the photos application BUT when you open the image it is purely white. I am confused by this.
Has anyone seen this before?
Thanks!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI have similar issue when I saved .png images using This function saves them in .jpg format and cuts their transparency.
You can save these images in your app's bundle Documents directory, this will keep images in correct format.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome