Skip to content

Instantly share code, notes, and snippets.

@haxpor
Created January 15, 2016 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haxpor/a44585fc49e1ae03edb1 to your computer and use it in GitHub Desktop.
Save haxpor/a44585fc49e1ae03edb1 to your computer and use it in GitHub Desktop.
get UIImage from CCRenderTexture
+(UIImage *)getUIImageOfGeneratedScore
{
CCSprite *socialShare = CCSprite::create("../bg-social-share.png");
int textureWidth = socialShare->getContentSize().width;
int textureHeight = socialShare->getContentSize().height;
socialShare->setPosition(ccp(textureWidth/2, textureHeight/2));
CCRenderTexture* renderer = CCRenderTexture::create(textureWidth, textureHeight);
renderer->begin();
socialShare->visit();
renderer->end();
bool isSuccess = renderer->saveToFile("socialScoreShare.png", kCCImageFormatPNG);
if (isSuccess)
{
CCLOG("Write to file successfully.");
}
UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%s", CCFileUtils::sharedFileUtils()->getWritablePath().append("socialScoreShare.png").c_str()]];
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment