Save CCRenderTexture screenshot to PhotoGallery or Convert CCRenderTexture to UIImage

Save CCRenderTexture screenshot to PhotoGallery or Convert CCRenderTexture to UIImage
0.0 0


Hello everyone,

I have a quick question. I want to save a screenshot to the iphone camera roll/photo gallery. According to the wiki, you generate a CCRenderTexture to make the screenshot. I know how to save an UIImage so maybe you have to convert it to a UIImage before saving. Is there anyone who has a solution to this problem?

Thanks in advance


Nevermind, found the solution.


How you did it? I am facing same problem. :frowning:


Dear John,
If you found the solution why don’t you post about that solution?
I think whether you were helped by this forum or not, it’s your responsibility to end up your thread by answering.
I’m not trying to blame you, I’m just talking about conscience.

Anyway, let’s get back to the original question.

It can be easily done by combining cocos2d-x and cocod2d-iphone.
(Because there’s already exist the function which converts rendered texture to UIImage on the cocos2d-iphone’s CCRenderTexture class)

I made CCRendererTextureEx in that way, and I’ll attache it.

Sample usage below - converting CCSprite to UIImage.

UIImage* UIImageFromCCSprite(CCSprite *sprite)
    CCSize size = sprite->getTexture()->getContentSizeInPixels();

    CCRenderTextureEx *renderer = CCRenderTextureEx::create(size.width, size.height);

    CCPoint originalAnchor = sprite->getAnchorPoint();

    renderer->beginWithClear(0, 0, 0, 0);


    UIImage *result = renderer->getUIImage();
    return result;

Please note that you can use this class in .mm file only.
You don’t need UIImage in .cpp file anyway. :slight_smile:


Hey , I’m using Cocos2d-x 3.2 ! It doesn’t have getUIImage() :(( what I must do now


Did you find any solution. ?
I am stuck at same position.