android开发 在JNI函数中引用Java类,将cxx复杂数据转换成jobjectArray,实现从JNI到Java的数据传输

引言:

JNI是Java可以调用高效的c++代码,但是在JNI函数中传递复杂数据类型十分的繁琐,一般情况下需要jobject作为中转,一维数组int[],float[]以及二维数组String[]可以实现方便的参数传入/传出。其他复杂的二、三维数组理论上可以使用jobjectarray实现参数传入/传出,可是实现过程中出现问题,可能是内存上的错误。
下面介绍一种通用方法,在JNI函数中引用Java类,将cxx复杂数据转换成jobjectArray,实现从JNI到Java的数据传输。

Step1:定义Java类接口

这里定义了一个目标检测的通用接口类。创建”OneDetection.java”如下:

package com.example.cuizhou.test01;

import android.graphics.Bitmap;

/**
 * Created by cuizhou on 18-1-11.
 */

public class OneDetection {
   
    private String mLabel;
    private float mConfidence;
    private int mLeft;
    private int mTop;
    private int mRight;
    private int mBottom;

    public OneDetection() {
    }

    /**
     * @param label      Label name
     * @param confidence A confidence factor between 0 and 1. This indicates how certain what has been found is actually the label.
     * @param l          The X coordinate of the left side of the result
     * @param t          The Y coordinate of the top of the result
     * @param r          The X coordinate of the right side of the result
     * @param b          The Y coordinate of the bottom of the result
     */
    public OneDetection(String label, float confidence, int l, int t, int r, int b) {
        mLabel = label;
        mLeft = l;
        mTop = t;
        mRight = r;
        mBottom = b;
        mConfidence = confidence;
    }

    /**
     * @return The X coordinate of the left side of the result
     */
    public int getLeft() {
        return mLeft;
    }

    /**
     * @return The Y coordinate of the top of the result
     */
    
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值