Hi,
I got a half black screen on my album, When i take screenShot.
I written following code below :-
@interface VBOverlayViewController : OverlayViewController {
UIButton *takePhoto;
}
@property (nonatomic,assign)UIButton *takePhoto;
//For Take a screen Shot
-(UIImage *)glToUIImage;
-(void)TakePhoto;
@implementation VBOverlayViewController
@synthesize takePhoto;
-(void)loadView
{
takePhoto = [[UIButton alloc]initWithFrame:CGRectMake(0, 14, 70, 70)];
// takePhoto.backgroundColor = [UIColor colorWithPatternImage:[]];
[takePhoto setTitle:@"Take Photo" forState:UIControlStateNormal];
[takePhoto.titleLabel setFont:[UIFont systemFontOfSize:12.0]];
[takePhoto addTarget:self action:@selector(TakePhoto) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:takePhoto];
}
-(UIImage *)glToUIImage
{
NSInteger myDataLength = 320 * 480 * 8;//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 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; x++) {
buffer2[(479 - y) * 320 * 4 + x] = buffer[y * 4 * 320 + x];//4
}
}
//make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL);
//prep the ingredients
int bitsPerComponent = 8;//8
int bitPerPixel = 32;//64
int bytePerRow = 4 * 320;//4
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
//make the cgimage
CGImageRef imageRef = CGImageCreate(320, 480, bitsPerComponent, bitPerPixel, bytePerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
NSLog(@"imageRef:-%@",imageRef);
//then make the uiImage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
NSLog(@"myImage:-%@",myImage);
return myImage;
}
-(void)TakePhoto
{
UIImage *image = [self glToUIImage];
NSLog(@"imge:-%@",image);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Get It!" message:@"Go to the Album." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
}
//EaglView.m-------------
@implementation EAGLView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = TRUE;
// eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
// [NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking,
// kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
// nil];
eaglLayer.drawableProperties = @{
kEAGLDrawablePropertyRetainedBacking: [NSNumber numberWithBool:YES],
kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8,
};
What I do, because I m doing all codes.Please guide me.
Thank you
Khushi
What is the problem with the source code I posted below?
N