Hi david thanks for replying. In the first time I actually used it as is. I red a little bit more and added the rest of the code (I hope so) this time the background became white but the drawn lines disappeared. I tried to check the buffer color at each point and replace it to 255 every time it's 0. That worked great, the background became white and the lines remained but their colors changed in a way I can not understand. I will appreciate if you can help me with that.
This is the code I wrote
-(void)saveCurrentScreenToPhotoAlbum {
int width = 768;
int height = 1024;
//glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
//glClear(GL_COLOR_BUFFER_BIT);
NSInteger myDataLength = width * height * 4;
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
NSLog(@"%d", buffer[0]);
for(int y = 0; y <height; y++) {
for(int x = 0; x <width * 4; x++) {
if (buffer[y * 4 * width + x]==0) {
buffer[y * 4 * width + x] = 250;
//buffer[y * 4 * width + x+1] = 250;
NSLog(@" = %i",y * 4 * width + x);
}
buffer2[(height - 1 - y) * width * 4 + x] = buffer[y * 4 * width + x];
// printf("%d %d %d\n",buffer[(height - 1 - y) * width * 4 + x],buffer[1],buffer[2]);
}
}
free(buffer); // YOU CAN FREE THIS NOW
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, releaseData);
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);
CGColorSpaceRelease(colorSpaceRef); // YOU CAN RELEASE THIS NOW
CGDataProviderRelease(provider); // YOU CAN RELEASE THIS NOW
UIImage *image = [[UIImage alloc] initWithCGImage:imageRef]; // change this to manual alloc/init instead of autorelease
CGImageRelease(imageRef); // YOU CAN RELEASE THIS NOW
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); // add callback for finish saving
}
Shani