This commit is contained in:
vision 2014-06-13 15:27:59 +08:00
Родитель 7e99121af7
Коммит 33fb1dd050
2 изменённых файлов: 21 добавлений и 3 удалений

Просмотреть файл

@ -409,14 +409,32 @@ void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, uint3
_orderOfArrival = 0;
}
bool RenderTexture::saveToFile(const std::string& filename)
bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA)
{
return saveToFile(filename,Image::Format::JPG);
std::string basename(filename);
std::transform(basename.begin(), basename.end(), basename.begin(), ::tolower);
if (basename.find(".png") != std::string::npos)
{
return saveToFile(filename, Image::Format::PNG, isRGBA);
}
else if (basename.find(".jpg") != std::string::npos)
{
if (isRGBA) CCLOG("RGBA is not supported for JPG format.");
return saveToFile(filename, Image::Format::JPG, false);
}
else
{
CCLOG("Only PNG and JPG format are supported now!");
}
return saveToFile(filename, Image::Format::JPG, false);
}
bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA)
{
CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG,
"the image can only be saved as JPG or PNG format");
if (isRGBA && format == Image::Format::JPG) CCLOG("RGBA is not supported for JPG format");
std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName;
_saveToFileCommand.init(_globalZOrder);

Просмотреть файл

@ -103,7 +103,7 @@ public:
/** saves the texture into a file using JPEG format. The file will be saved in the Documents folder.
Returns true if the operation is successful.
*/
bool saveToFile(const std::string& filename);
bool saveToFile(const std::string& filename, bool isRGBA = true);
/** saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder.
Returns true if the operation is successful.