【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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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下分享一张图片


<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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 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, 137, 207);"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/linchaolong/article/details/44452205#L13" rel="#L13" style="text-decoration: none; color: rgb(12, 137, 207);"> 13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/linchaolong/article/details/44452205#L14" rel="#L14" style="text-decoration: none; color: rgb(12, 137, 207);"> 14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/linchaolong/article/details/44452205#L15" rel="#L15" style="text-decoration: none; color: rgb(12, 137, 207);"> 15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/linchaolong/article/details/44452205#L16" rel="#L16" style="text-decoration: none; color: rgb(12, 137, 207);"> 16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/linchaolong/article/details/44452205#L17" rel="#L17" style="text-decoration: none; color: rgb(12, 137, 207);"> 17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/linchaolong/article/details/44452205#L18" rel="#L18" style="text-decoration: none; color: rgb(12, 137, 207);"> 18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/linchaolong/article/details/44452205#L19" rel="#L19" style="text-decoration: none; color: rgb(12, 137, 207);"> 19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/linchaolong/article/details/44452205#L20" rel="#L20" style="text-decoration: none; color: rgb(12, 137, 207);"> 20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/linchaolong/article/details/44452205#L21" rel="#L21" style="text-decoration: none; color: rgb(12, 137, 207);"> 21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/linchaolong/article/details/44452205#L22" rel="#L22" style="text-decoration: none; color: rgb(12, 137, 207);"> 22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/linchaolong/article/details/44452205#L23" rel="#L23" style="text-decoration: none; color: rgb(12, 137, 207);"> 23</a>
           
           
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 )));
}
 来自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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值