CaptureScreen in cocos-2d c ++ - how to use or save a captured image?

I want to have a button in my (iOS) application that takes a screenshot of the current screen and then attaches it to a text message.

As I already saw in this other application ...

enter image description here

I have a message sending, and I think that a screenshot works for me, but I do not know where the screenshot is saved or how to use it.

My messaging is invoked using a button in the application ...

void GameOverScene::messageCallBack(cocos2d::Ref *sender) {
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(ALL_BUTTONS_CLICK_SOUND_NAME);
utils::captureScreen( CC_CALLBACK_2(GameOverScene::afterCaptured, this), "screenshot.png" );
__String *messageTextOne = __String::create("sms:&body=Hey,%20I%20just%20hit%20a%20score%20of%20");
__String *messageTextTwo = __String::createWithFormat("%i", score);
__String *messageURL = __String::createWithFormat("%s%s", messageTextOne->getCString(), messageTextTwo->getCString());
Application::getInstance()->openURL(messageURL->getCString());
}

and screenshot function ...

void GameOverScene::afterCaptured( bool succeed, const std::string &outputFile ) {
if (succeed) {
    log("Screen capture succeeded");
    Size screenSize = Director::getInstance()->getWinSize();
    RenderTexture * tex = RenderTexture::create(screenSize.width, screenSize.height);
    tex->setPosition(screenSize.width/2, screenSize.height/2);
    tex->begin();
    this->getParent()->visit();
    tex->end();
    tex->saveToFile("Image_Save.png", Image::Format::PNG);
} else {
    log("Screen capture failed");
}
}

I get a message in the “Screen Capture Successfully” console, and my message application opens with a pre-populated text message.

, , , , , .

+6
2

, . , iExplorer, , "". , .

, UIImageWriteToSavedPhotosAlbum

.: iPhone?

AppController.m . objc- ++. UIImage, uiimage , , , .

+1

- , :

void  CustomLayerColor::saveFile(Node*node, std::string fileName, const renderTextureCallback& callBack) {
    float renderTextureWidth = node->getBoundingBox().size.width;
    float renderTextureHeight = node->getBoundingBox().size.height;        

    RenderTexture * renderTexture = RenderTexture::create(renderTextureWidth,renderTextureHeight);
    renderTexture->begin();

    node->visit();

    renderTexture->end();
    renderTexture->saveToFile(fileName, Image::Format::PNG, true,callBack);
}

void CustomLayerColor::onSaveFileCallBack(RenderTexture * mRenderTexture, const std::string& savedFileNameWithFullPath) {

}
0

Source: https://habr.com/ru/post/1017366/


All Articles