bool CCImage::saveToFile(const char *pszFilePath, bool bIsToRGB) { bool bRet = false; do { CC_BREAK_IF(NULL == pszFilePath); std::string strFilePath(pszFilePath); CC_BREAK_IF(strFilePath.size() <= 4); std::string strLowerCasePath(strFilePath); for (unsigned int i = 0; i < strLowerCasePath.length(); ++i) { strLowerCasePath[i] = tolower(strFilePath[i]); } if (std::string::npos != strLowerCasePath.find(".png")) { CC_BREAK_IF(!_saveImageToPNG(pszFilePath, bIsToRGB)); } else if (std::string::npos != strLowerCasePath.find(".jpg")) { CC_BREAK_IF(!_saveImageToJPG(pszFilePath)); } else { break; } bRet = true; } while (0); return bRet; }
bool Image::saveToFile(const char *pszFilePath, bool bIsToRGB) { //only support for Texture2D::PixelFormat::RGB888 or Texture2D::PixelFormat::RGBA8888 uncompressed data if (isCompressed() || (m_eRenderFormat != Texture2D::PixelFormat::RGB888 && m_eRenderFormat != Texture2D::PixelFormat::RGBA8888)) { CCLOG("cocos2d: Image: saveToFile is only support for Texture2D::PixelFormat::RGB888 or Texture2D::PixelFormat::RGBA8888 uncompressed data for now"); return false; } bool bRet = false; do { CC_BREAK_IF(NULL == pszFilePath); std::string strFilePath(pszFilePath); CC_BREAK_IF(strFilePath.size() <= 4); std::string strLowerCasePath(strFilePath); for (unsigned int i = 0; i < strLowerCasePath.length(); ++i) { strLowerCasePath[i] = tolower(strFilePath[i]); } if (std::string::npos != strLowerCasePath.find(".png")) { CC_BREAK_IF(!saveImageToPNG(pszFilePath, bIsToRGB)); } else if (std::string::npos != strLowerCasePath.find(".jpg")) { CC_BREAK_IF(!saveImageToJPG(pszFilePath)); } else { break; } bRet = true; } while (0); return bRet; }