如何在Android上获取Cocos2d-x的屏幕快照保存路径 [英] How to get screenshot saved path by Cocos2d-x on android
问题描述
我使用saveToFile方法保存屏幕截图,并检查CCLOG,它显示/data/data/com.xxx.xxx/files/xxx.png
I use saveToFile method to save screenshot, and I check CCLOG, it shows /data/data/com.xxx.xxx/files/xxx.png
但是,当我使用Java获取此文件时,它显示没有这样的文件或目录".... 我该怎么办?
However, when I use Java to get this file, it says "No such file or directory".... What can I do?
推荐答案
我也遇到了同样的问题.当我尝试renderTexture->saveToFile
方法时,无法提交Java路径.没关系,我使用getWritablePath()
或直接设置路径"/sdcard/Android/data/com.xxx.xxx/snapshot.jpg"
.
我还尝试根据 Facundo Olano 的建议解决此问题.但是CCImage
仅构成纯黑色图像.
最后,我将这两种方法结合起来.首先,我用renderTexture->saveToFile
制作图像:
I also had the same problem. When I try renderTexture->saveToFile
method, I can't submit path to java. No matter, I used getWritablePath()
or set the path directly "/sdcard/Android/data/com.xxx.xxx/snapshot.jpg"
.
I try also to solve this problem on the advice of Facundo Olano. But CCImage
compose only solid black image.
Finally I combine this two methods. First, I make an image by renderTexture->saveToFile
:
void MyScene::pressFaceBook()
{
...
RenderTexture* renderTexture = RenderTexture::create(sharedImage->getBoundingBox().size.width, sharedImage->getBoundingBox().size.height, Texture2D::PixelFormat::RGBA8888);
renderTexture->begin();
sharedImage->visit();
renderTexture->end();
renderTexture->saveToFile("snapshot.jpg", Image::Format::JPG);
const std::string fullpath = FileUtils::getInstance()->getWritablePath() + "snapshot.jpg";
sharedImage->setVisible(false);
this->runAction(Sequence::create(DelayTime::create(2.0f),
CallFunc::create(std::bind(&MyScene::shareFaceBook, this, fullpath)),
NULL));
}
然后我将initWithImageFile
与传输的文件名一起使用:
And then I use initWithImageFile
with the transferred file name:
void MyScene::shareFaceBook(const std::string& outputFile)
{
const std::string joutputFile = "/sdcard/Android/data/com.xxx.xxx/snapshot.jpg";
cocos2d::Image* img = new Image;
img->initWithImageFile(fullpath);
img->saveToFile(joutputFile);
CC_SAFE_DELETE(img);
singleton->shareFaceBook(joutputFile);
}
需要2秒的延迟才能捕获屏幕截图. 当然,必须用您的应用名称代替com.xxx.xxx.
A delay of 2 seconds is needed to capture the screenshot. Of course, instead com.xxx.xxx you must substitute your app name.
这篇关于如何在Android上获取Cocos2d-x的屏幕快照保存路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!