百度一下其实有很多关于Creator 原生平台截屏的相关文章,但是为什么我还要写这篇文章呢?因为今天遇到一个大坑了。
网上其它文章中介绍的截图代码其实都是可用的,坑的就是在安卓平台下需要微信分享时出现问题了。
微信分享需要读取本地图片,但是通过查看CCRenderTexture.cpp得知renderTexture.saveToFile保存的文件其实是在你游戏应用目录下的,微信读取不到。所以会造成能拉起微信分享,但是一直显示“正在发送中”的情况。
bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA, std::function<void (RenderTexture*, const std::string&)> callback)
{
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");
_saveFileCallback = callback;
std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName;
_saveToFileCommand.init(_globalZOrder);
_saveToFileCommand.func = CC_CALLBACK_0(RenderTexture