Created
January 15, 2016 17:01
-
-
Save haxpor/a44585fc49e1ae03edb1 to your computer and use it in GitHub Desktop.
get UIImage from CCRenderTexture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(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