mirror of https://github.com/axmolengine/axmol.git
captureScreen compatible, saveFile at offthread
This commit is contained in:
parent
b956637c74
commit
e91b7240e6
|
@ -163,17 +163,22 @@ void captureNode(Node* startNode, std::function<void(RefPtr<Image>)> imageCallba
|
|||
}
|
||||
|
||||
// [DEPRECATED]
|
||||
void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename)
|
||||
void captureScreen(std::function<void(bool, const std::string&)> afterCap, const std::string& filename)
|
||||
{
|
||||
std::string outfile;
|
||||
if (FileUtils::getInstance()->isAbsolutePath(filename))
|
||||
outfile = filename;
|
||||
else
|
||||
outfile = FileUtils::getInstance()->getWritablePath() + filename;
|
||||
captureScreen([=,fullPath=std::move(outfile)](RefPtr<Image> image) {
|
||||
bool ok = image && image->saveToFile(fullPath, false);
|
||||
|
||||
afterCaptured(ok, fullPath);
|
||||
captureScreen([_afterCap = std::move(afterCap), _outfile = std::move(outfile)](RefPtr<Image> image) mutable {
|
||||
AsyncTaskPool::getInstance()->enqueue(AsyncTaskPool::TaskType::TASK_IO, [_afterCap = std::move(_afterCap), image = std::move(image), _outfile = std::move(_outfile)]() mutable
|
||||
{
|
||||
bool ok = image->saveToFile(_outfile);
|
||||
Director::getInstance()->getScheduler()->performFunctionInCocosThread([ok, _afterCap = std::move(_afterCap), _outfile = std::move(_outfile)]{
|
||||
_afterCap(ok, _outfile);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace utils
|
|||
* base filename ("hello.png" etc.), don't use a relative path containing directory names.("mydir/hello.png" etc.).
|
||||
* @since v4.0
|
||||
*/
|
||||
CC_DLL void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename);
|
||||
CC_DLL void captureScreen(std::function<void(bool, const std::string&)> afterCap, const std::string& filename);
|
||||
|
||||
/** Find children by name, it will return all child that has the same name.
|
||||
* It supports c++ 11 regular expression. It is a helper function of `Node::enumerateChildren()`.
|
||||
|
|
Loading…
Reference in New Issue