2017-05-18 36 views
6

我想在我的(iOS)應用程序中有一個按鈕,它會截取當前屏幕的屏幕截圖,然後將其附加到短信。cocos-2d captureScreen C++ - 如何使用或保存捕獲的圖像?

就像我在這個其他應用程序所看到的......

enter image description here

我有消息發送的工作,我想我有截圖的工作,但我不知道在哪裏截圖保存或如何使用它。

我的消息發送是從應用程序的按鈕叫...

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()); 
} 

和截圖功能是...

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"); 
} 
} 

我得到在控制檯消息「截屏成功「,我的消息應用程序打開預填的文本消息。

我需要做的是添加屏幕截圖到這條消息,但我不知道該怎麼做,或屏幕截圖保存的位置,或者如何使用保存的屏幕截圖。

回答

1

如果成功將其保存在私人應用程序目錄中。使用像iExplorer這樣的軟件,找到你的應用程序,它應該在Documents目錄內。如果你想在照片中看到它,你可以在那裏手動添加它。

爲了實現這一點,你必須調用 UIImageWriteToSavedPhotosAlbum

見:How to save picture to iPhone photo library?

你必須創建一個AppController.m功能,從這裏使用它。你可以從C++調用objc代碼。它需要UIImage,所以首先你必須通過文件路徑並從它加載uiimage,然後添加到圖庫。

+0

我最終想與這個畫面做的是將其發送到iPhone的消息應用程序,因此它可以作爲一個被髮送出去文本。我將如何去截圖發送消息? – Richard

+0

試試這個:http://stackoverflow.com/questions/21699756/send-picture-text-in-imessage-in-ios-programatically – Makalele

0

您可以使用這樣的事情來獲得圖像的保存路徑:

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) { 

} 
相關問題