iPad 3 save screenshot problem (Black)

I’m having problem to save an in-game screenshot in iPad3.
The saved picture, all black.
But its working properly in iPad 1 and iPhone 3GS.
I am using Cocos2dx 2.03. iOS 6.

Here is my code

    //Create un buffer for pixels
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    GLuint bufferLenght=size.width*size.height*4;
    GLubyte *buffer = (GLubyte *) malloc(bufferLenght);

    //Read Pixels from OpenGL
    glReadPixels(0,0,size.width,size.height,GL_RGBA,GL_UNSIGNED_BYTE,buffer);
    //Make data provider with data.
    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, bufferLenght, NULL);

    //Configure image
    int bitsPerComponent = 8;
    int bitsPerPixel = 32;
    int bytesPerRow = 4 * size.width;
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
    CGImageRef iref = CGImageCreate(size.width,size.height,bitsPerComponent,bitsPerPixel,bytesPerRow,colorSpaceRef,bitmapInfo,provider,NULL,NO,renderingIntent);

    uint32_t *pixels = (uint32_t *)malloc(bufferLenght);
    CGContextRef context = CGBitmapContextCreate(pixels, size.width, size.height, 8, size.width*4, CGImageGetColorSpace(iref), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    CGContextTranslateCTM(context,0, size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    CGContextDrawImage(context, CGRectMake(0.0, 0.0, size.width, size.height), iref);
    UIImage *outputImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)];

    //Dealloc
    CGDataProviderRelease(provider);
    CGImageRelease(iref);
    CGContextRelease(context);
    free(buffer);
    free(pixels);

    UIImageWriteToSavedPhotosAlbum(outputImage, nil, nil, nil);

Did you enabled retina?
May be you should checkout the value of size.

Minggo Zhang wrote:

Did you enabled retina?
May be you should checkout the value of size.

No, in appdelegate the retina setter is still in comment tag
I’ve log the size from CCDirector::sharedDirector()->getWinSize() and it return 1024 x 768

I have tried to save the screenshot in iPad 6.0 simulator, and it works fine.

I found some people have this same problem.
I tried to port it to c+*, but i dont have a clue the type that equivalent to UIImage in cocos2dx. Any clue?
<pre>
(UIImage*) screenshotWithStartNode:startNode
{
.nextDeltaTimeZero = YES;
CGSize winSize = .winSize;
CCRenderTexture** rtx =
[CCRenderTexture renderTextureWithWidth:winSize.width
height:winSize.height];
[rtx begin];
[startNode visit];
[rtx end];

return [rtx getUIImage];
}

You can call it like this
CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCNode *n = [scene.children objectAtIndex:0];
UIImage *img = [AppController screenshotWithStartNode:n];

You can use CCImage.
Diori Cergy Castali wrote:

I found some people have this same problem.
I tried to port it to c++, but i dont have a clue the type that equivalent to UIImage in cocos2dx. Any clue?
>
[…]
>
You can call it like this
[…]

James Chen wrote:

You can use CCImage.
Diori Cergy Castali wrote:
> I found some people have this same problem.
> I tried to port it to c++, but i dont have a clue the type that equivalent to UIImage in cocos2dx. Any clue?
>
> […]
>
> You can call it like this
> […]

I tried to replace the UIimage with the CCImage to this function, but the type is not compatible.
Is there any function in cocos2dx is equivalent to “UIImageWriteToSavedPhotosAlbum()” ?

UIImageWriteToSavedPhotosAlbum(outputImage, nil, nil, nil);

I’ve tried

CCImage *img = rtx->newCCImage(); // rtx is rendertexture
img->saveToFile("MysteryMachine876.png");

CCRenderTexture* rtx = CCRenderTexture::renderTextureWithWidthAndHeight(winSize.width, winSize.height);
rtx->begin();
n->visit();
rtx->end();
rtx->saveToFile("MysteryMachine.png", kCCImageFormatPNG);

But no one saves the screenshot to file like UIImageWriteToSavedPhotosAlbum()

Hi,

I have the same problem. I want to make an in-game screenshot in iPad 3 and the image is not saved.
Do you know how can I sove it?