• 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

  • 相关阅读:
    搜索入门
    计算几何基础
    对“学生自行组队,共同完成实验”的一些思考感慨
    20145213《信息安全系统设计》第十一周学习总结
    20145213《信息安全系统设计基础》第十周学习总结
    记与舍友摩擦的一两事儿
    20145213《信息安全系统设计》第九周学习总结下篇
    20145213《信息安全基础设计》第九周学习总结上篇
    20145213《信息安全设计系统》实验报告一
    20145213《信息安全系统设计基础》第八周学习总结下篇
  • 原文地址:https://www.cnblogs.com/wendao/p/adr_cpp_invoke_java_send.html
Copyright © 2020-2023  润新知