diff --git a/cocos2dx/include/CCRenderTexture.h b/cocos2dx/include/CCRenderTexture.h index 15c6bc4c77..a7ecd0b367 100644 --- a/cocos2dx/include/CCRenderTexture.h +++ b/cocos2dx/include/CCRenderTexture.h @@ -85,7 +85,8 @@ public: void clear(float r, float g, float b, float a); /** saves the texture into a file */ - bool saveBuffer(const char *name); + // para szFilePath the absolute path to save + bool saveBuffer(const char *szFilePath); /** saves the texture into a file. The format can be JPG or PNG */ bool saveBuffer(const char *name, int format); diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp index fd2b81a7ff..78911e3007 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.cpp +++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp @@ -216,13 +216,21 @@ void CCRenderTexture::clear(float r, float g, float b, float a) this->end(); } -bool CCRenderTexture::saveBuffer(const char *name) +bool CCRenderTexture::saveBuffer(const char *szFilePath) { - return this->saveBuffer(name, kCCImageFormatJPG); + bool bRet = false; + + CCImage *pImage = new CCImage(); + if (pImage != NULL && getUIImageFromBuffer(pImage)) + { + bRet = pImage->saveToFile(szFilePath); + } + + CC_SAFE_DELETE(pImage); + return bRet; } bool CCRenderTexture::saveBuffer(const char *fileName, int format) { - bool bRet = false; CCAssert(format == kCCImageFormatJPG || format == kCCImageFormatPNG, "the image can only be saved as JPG or PNG format");