void CCRenderTexture::listenToBackground(cocos2d::CCObject *obj) { #if CC_ENABLE_CACHE_TEXTURE_DATA CC_SAFE_DELETE(m_pUITextureImage); // to get the rendered texture data m_pUITextureImage = newCCImage(false); if (m_pUITextureImage) { const CCSize& s = m_pTexture->getContentSizeInPixels(); VolatileTexture::addDataTexture(m_pTexture, m_pUITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s); if ( m_pTextureCopy ) { VolatileTexture::addDataTexture(m_pTextureCopy, m_pUITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s); } } else { CCLOG("Cache rendertexture failed!"); } glDeleteFramebuffers(1, &m_uFBO); m_uFBO = 0; #endif }
bool CCRenderTexture::saveToFile(const char *szFilePath) { bool bRet = false; CCImage *pImage = newCCImage(); if (pImage) { bRet = pImage->saveToFile(szFilePath, kCCImageFormatJPEG); } CC_SAFE_DELETE(pImage); return bRet; }
bool CCRenderTexture::saveToFile(const char *fileName, tCCImageFormat format) { bool bRet = false; CCAssert(format == kCCImageFormatJPEG || format == kCCImageFormatPNG, "the image can only be saved as JPG or PNG format"); CCImage *pImage = newCCImage(); if (pImage) { std::string fullpath = CCFileUtils::sharedFileUtils()->getWriteablePath() + fileName; bRet = pImage->saveToFile(fullpath.c_str(), true); } CC_SAFE_DELETE(pImage); return bRet; }