I've been working with OpenGL ES to modify an application which allows to capture a user's signature. Now i can draw freehand on the screen but now i need to keep that signature into an image. I found this code which just draws a completely black image, i'm new to OpenGL i hope that somebody can help me...
Code:
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);
After a new search in this forum i found a possible solution, the inconvenient of this is when i see the preview of my image is completely black... Just replace the line:
I am having a similar problem but it is stranger.
I 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?
Please check what is the saved image format ?
I have similar issue when I saved .png images using
Quote:
UIImageWriteToSavedPhotosAlbum()
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.