【Cocos2d-x】截图分享功能

Cocos2d-x截图实现


<a target=_blank id="L1" href="http://blog.csdn.net/linchaolong/article/details/44452205#L1" rel="#L1" style="text-decoration: none; color: rgb(12,137,207);">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/linchaolong/article/details/44452205#L2" rel="#L2" style="text-decoration: none; color: rgb(12,207);">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/linchaolong/article/details/44452205#L3" rel="#L3" style="text-decoration: none; color: rgb(12,207);">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/linchaolong/article/details/44452205#L4" rel="#L4" style="text-decoration: none; color: rgb(12,207);">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/linchaolong/article/details/44452205#L5" rel="#L5" style="text-decoration: none; color: rgb(12,207);">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/linchaolong/article/details/44452205#L6" rel="#L6" style="text-decoration: none; color: rgb(12,207);">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/linchaolong/article/details/44452205#L7" rel="#L7" style="text-decoration: none; color: rgb(12,207);">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/linchaolong/article/details/44452205#L8" rel="#L8" style="text-decoration: none; color: rgb(12,207);">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/linchaolong/article/details/44452205#L9" rel="#L9" style="text-decoration: none; color: rgb(12,207);">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/linchaolong/article/details/44452205#L10" rel="#L10" style="text-decoration: none; color: rgb(12,207);"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/linchaolong/article/details/44452205#L11" rel="#L11" style="text-decoration: none; color: rgb(12,207);"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/linchaolong/article/details/44452205#L12" rel="#L12" style="text-decoration: none; color: rgb(12,207);"> 12</a>
           
           
#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 );
来自CODE的代码片
Cocos2d-x截图实现.cpp
图片将会保存在data/data/包名/files目录下。


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 ,240)">"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 )));
}
来自CODE的代码片
Android下分享一张图片.cpp


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。


原文:http://blog.csdn.net/linchaolong/article/details/44452205

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...