android cocos2dx游戲-添加截屏並分享微博功能


  又到了選擇的時候,元宵節,公交遇賊,錢包里的身份證銀行卡,統統被偷;被偷了,瞬間感覺“輕松了”,任何情況下我都可能回到原點,不是嗎?不要擔心選擇必然所要做的放棄。

public class ShareSupport {
// when you want to use share(),firstly you should init acty.
public static Activity acty;


public static void share() {
new Thread(new Runnable(){

@Override
public void run() {
Intent intent = new Intent("android.intent.action.SEND");
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
intent.putExtra(Intent.EXTRA_TEXT, "終於可以了!!!");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:////data/data/" + acty.getApplicationInfo().packageName+ "/share.png"));
Log.i("debug", "/data/data/" + acty.getApplicationInfo().packageName+ "/share.png");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
acty.startActivity(Intent.createChooser(intent, "分享"));
}

}).start();
}
}

拿出以前寫android時的分享代碼。

#include "jni_interfaces.h"
#include <android/jni/JniHelper.h>

extern "C" {
void Share()
{
cocos2d::JniMethodInfo jni_method_info;
cocos2d::JniHelper::getStaticMethodInfo(jni_method_info,"com/hortor/support/ShareSupport","share","()V");

if (jni_method_info.methodID)
{
jni_method_info.env->CallStaticVoidMethod(jni_method_info.classID, jni_method_info.methodID);
}
}
}

c++代碼越寫越簡潔了,刪掉很多冗雜的地方。

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
Share();
CCLog("share ok");
#endif

在分享按鈕初調用jni_interfaces中的Share()函數。

 ok不過有時,程序分享完會出現崩潰。

02-10 10:22:59.976: A/libc(2565): Fatal signal 11 (SIGSEGV) at 0x54e68000 (code=1)


看到群里有問, 如何從序列幀中獲取一張圖片,
我貼出游戲中截圖代碼:

    CCSize size = CCDirector::sharedDirector()->getWinSize();
CCRenderTexture* in_texture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height,kCCTexture2DPixelFormat_RGBA8888);
in_texture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
in_texture->setPosition( ccp(size.width/2, size.height/2) );
in_texture->setAnchorPoint( ccp(0.5f,0.5f) );

in_texture->begin();
this->visit();
in_texture->end();

CCLog("%d",in_texture->saveBuffer(kCCImageFormatPNG,"share.png",0,0,800,480));


 

write by fgd


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM