add image format check for Image::saveToFile in CCImage-ios.mm (#18986)

IOS保存灰度图崩溃
This commit is contained in:
verketh 2018-09-10 16:35:31 +08:00 committed by leda
parent 3c8c5139c1
commit 482c9eb8ca
1 changed files with 6 additions and 0 deletions

View File

@ -40,6 +40,12 @@ NS_CC_BEGIN
bool cocos2d::Image::saveToFile(const std::string& filename, bool isToRGB)
{
//only support for Texture2D::PixelFormat::RGB888 or Texture2D::PixelFormat::RGBA8888 uncompressed data
if (isCompressed() || (_renderFormat != Texture2D::PixelFormat::RGB888 && _renderFormat != 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 saveToPNG = false;
bool needToCopyPixels = false;