【Cocos2d-x】截圖分享功能
阿新 • • 發佈:2019-01-07
Cocos2d-x截圖實現
圖片將會儲存在data/data/包名/files目錄下。#include "cocos2d.h" USING_NS_CC; // 設定紋理寬、高、畫素質量 CCRenderTexture* tx = CCRenderTexture::create(CCDirector::sharedDirector()->getWinSize().width, CCDirector::sharedDirector()->getWinSize().height, kCCTexture2DPixelFormat_RGBA8888); tx->begin(); CCDirector::sharedDirector()->getRunningScene()->visit(); tx->end(); tx->saveToFile(path, kCCImageFormatPNG);
Android下分享一張圖片
Intent shareIntent = new Intent(Intent.ACTION_SEND); //shareIntent.putExtra(Intent.EXTRA_TEXT, 文字); String imgPath = 圖片路徑; File file = new File(imgPath); if (file.exists()) { try { //一般情況下,儲存的圖片檔案許可權為rw- rw- rw-(外部可讀寫),但有的機型可能是rw- --- ---(外部不可讀寫),如果是後者會分享失敗,因為外部不能讀取這張圖片。為了保證正常分享,需要通過chmod命令修改圖片檔案的許可權。 // 修改檔案許可權為-rw-r--r--,外部可讀 Process p = Runtime.getRuntime().exec("chmod 644 "+imgPath); int status = p.waitFor(); //讓當前執行緒等待 if (status == 0) { // 返回0表示正常終止 Log.d(TAG, "chmod succeed"); } else { Log.d(TAG, "chmod failure"); } } catch (Exception e) { e.printStackTrace(); } Uri uri = Uri.fromFile(file); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/png"); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.SHARE))); }
linux系統下的檔案許可權
一般情況下android下的每一個應用程式都是一個獨立的使用者,對應一個獨立的組。一個檔案的許可權由3組3個二進位制位表示。
位置0 |
- 代表檔案 d 代表目錄 |
位置1-3(當前使用者) |
r 可讀;w 可寫;x 可執行 |
位置4-6(當前使用者所在的組) |
r 可讀;w 可寫;x 可執行 |
位置7-9(其他使用者的許可權) |
r 可讀;w 可寫;x 可執行 |
-代表0
d、r、w、x都是代表1
如:rw-r--r--表示當前使用者可讀可寫,使用者所在組可讀,其他使用者可讀。對應的十進位制值為 6 4 4。