我用的是一個萬能轉換法,原理是先用CCSprite加載.pvr.ccz,然后把它繪制到一個CCRenderTexture上,然后再保存到文件里。這方法其實不只.pvr.ccz文件,其他所有能被cocos2dx直接加載的文件都可以用這種轉換。有個弊端就是可能跟源文件數據稍有些差異(我這個就是看起來有點白邊)。
用法是:比如有個文件夾叫Image,里面有個文件叫1.pvr.ccz。把Image文件夾拖拽到PngConverter.exe圖標上。然后會在Image的旁邊生成一個文件夾叫Image_png(里面有個文件叫1.png)
注意:目錄不能帶中文!!!!
生成的png文件名字不全的bug已經修正。
最近發現有些不道德行為,轉載請注明出處:http://www.cnblogs.com/mrblue/p/3420189.html
附上關鍵源碼
bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); this->addChild(pLabel, 1); {//convert const char* pszSuffix = ".pvr.ccz"; int nStartPos = -1; while ( nStartPos=g_Param.find('\\',nStartPos+1),-1!=nStartPos ) { g_Param.replace(nStartPos,1,"/"); } std::string strFileFilter = g_Param+"/*"+pszSuffix; _finddata_t fileDir; long lfDir; if((lfDir = _findfirst(strFileFilter.c_str(),&fileDir))==-1l) { char szMsg[128] = {0}; sprintf(szMsg,"Please drag a folder which contains \"%s\" files onto this application's icon" ,pszSuffix); pLabel->setString(szMsg); } else { std::string strSaveFolderPath = g_Param+"_png/"; BOOL ret = CreateDirectoryA(strSaveFolderPath.c_str(), NULL); if (!ret && ERROR_ALREADY_EXISTS != GetLastError()) { CC_ASSERT(false); } int nFileNum = 0; do { std::string strFileName = fileDir.name; std::string strFilePath = g_Param+'/'+strFileName; CCSprite *img = CCSprite::create(strFilePath.c_str()); img->setPosition(ccp(0,0)); img->setAnchorPoint(ccp(0,0)); CCSize sz = img->getContentSize(); CCRenderTexture* pRT = CCRenderTexture::create(sz.width, sz.height, kCCTexture2DPixelFormat_RGBA8888); pRT->clear(1,1,1,0); pRT->begin(); img->visit(); pRT->end(); std::string strSaveFile = strFileName.substr(0,strFileName.rfind(pszSuffix)); strSaveFile+=".png"; std::string strSaveFullPath = strSaveFolderPath+strSaveFile; CCImage *pImage = pRT->newCCImage(true); pImage->saveToFile(strSaveFullPath.c_str(), false); CC_SAFE_DELETE(pImage); CCLOG("%s",fileDir.name); nFileNum++; }while( _findnext( lfDir, &fileDir ) == 0 ); char szMsg[128] = {0}; sprintf(szMsg,"%d files have been converted",nFileNum); pLabel->setString(szMsg); } } return true; }