Solved! Go to Solution.
Humza,
I have tried that but maybe I am putting it in the wrong spot or doing something else wrong. I am attaching my code for both calling the get image process and the process itself. Any help would be greatly appreciated.
Calling-(void) PrintPermitFinal { CAEAGLLayer *eaglLayer = (CAEAGLLayer *) self.mapView.layer; eaglLayer.drawableProperties = @{ kEAGLDrawablePropertyRetainedBacking: [NSNumber numberWithBool:YES], kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8 }; // reset buttons [selfsettoInitialMapView]; // create image and pdf UIImage *screenshot = [[UIImage alloc] initWithData:[self getImage]]; // use clip path Rect to clip image to right size CGImageRef imageref = CGImageCreateWithImageInRect([screenshot CGImage], clipRect); screenshot = [UIImage imageWithCGImage:imageref]; //save image to photo album for testing only UIImageWriteToSavedPhotosAlbum(screenshot,self,@selector(image:didFinishSavingWithError:contextInfo:),nil); //Send Image to Dictionary if (AppDelagate.PermitImages == nil) { AppDelagate.PermitImages = [[NSMutableDictionaryalloc] init]; } NSString *Key= [selfCreatePermitID:[AppDelagate.GraphicToPrint.allAttributesvalueForKey:@"Full_Name"] AndAddress:[AppDelagate.GraphicToPrint.allAttributesvalueForKey:@"Owner_Address"]]; [AppDelagate.PermitImages setObject:screenshot forKey:Key]; self.tabBarController.selectedViewController = [self.tabBarController.viewControllersobjectAtIndex:1]; }
Getting the image virtually unchanged from Bernese- (NSData *)getImage { GLint width; GLint height; glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width); glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height); NSInteger myDataLength = width * height * 4; // allocate array and read pixels into it. GLubyte *buffer = (GLubyte *) malloc(myDataLength); glReadPixels(0, 0, width, height, 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 < height; y++) { for(int x = 0; x < width * 4; x++) { buffer2[((height - 1) - y) * width * 4 + x] = buffer[y * 4 * width + 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 * width; CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; // make the cgimage CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); // then make the uiimage from that UIImage *myImage = [[UIImage alloc] initWithCGImage:imageRef]; NSData *iDat = UIImageJPEGRepresentation(myImage, 0); CGImageRelease(imageRef); CGDataProviderRelease(provider); CGColorSpaceRelease(colorSpaceRef); free(buffer); free(buffer2); return iDat; }
Cheers,
Jeff
CAEAGLLayer *eaglLayer = (CAEAGLLayer *) theMap.layer;
eaglLayer.drawableProperties = @{
kEAGLDrawablePropertyRetainedBacking: [NSNumber numberWithBool:YES],
kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8
};- (NSData *)getImage
{
GLint width;
GLint height;
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height);
NSInteger myDataLength = width * height * 4;
// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, width, height, 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 < height; y++)
{
for(int x = 0; x < width * 4; x++)
{
buffer2[((height - 1) - y) * width * 4 + x] = buffer[y * 4 * width + 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 * width;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// then make the uiimage from that
UIImage *myImage = [[UIImage alloc] initWithCGImage:imageRef];
NSData *iDat = UIImageJPEGRepresentation(myImage, 0);
CGImageRelease(imageRef);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpaceRef);
free(buffer);
free(buffer2);
return iDat;
}