从Java类containg的Andr​​oid类错误创建C头文件 [英] Error creating C header file from Java class containg Android class

查看:200
本文介绍了从Java类containg的Andr​​oid类错误创建C头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在一个Android的应用程序在那里我有一个包含一个Java类android.graphics.Bitmap包

我想用JAVAH但得到一个错误创建一个头文件:

 类android.graphics.Bitmap未找到


解决方案

我认为你正试图开发一种OpenCV的应用程序。

所以,你基本上要调用来自OpenCV的库方法,未用Java实现还,但作为本地C或C ++方法。
尽量规避,因为JNI的调用是昂贵的。

 的#include< jni.h>
#包括LT&; opencv2 /核心/ core.hpp>
#包括LT&; opencv2 / imgproc / imgproc.hpp>
#包括LT&; opencv2 / features2d / features2d.hpp>
#包括LT&;矢量>使用命名空间std;
使用命名空间的简历;为externC{
JNIEXPORT无效JNICALL JAVA_ [你] _ [包装] _ [玉米] _ [类] _【制法】(JNIEnv的* ENV,jobject THIZ,jlong​​ addrGray,jlong​​ addrRgba)
{
//做的东西
}

您可以从您的Java类现在调用这个方法:

 公共本地无效的方法(长matAddrGr,长matAddrRgba);

I am working on an app in android where I have a Java class containing android.graphics.Bitmap package

I want to create a header file using javah but getting an error:

Class android.graphics.Bitmap not found

解决方案

I think you are trying to develop an openCV app.

So you basically want to call methods from the openCV library, that are not implemented in java yet, but are available as native C or C++ methods. Try to circumvent that, because jni-calls are expensive.

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>

using namespace std;
using namespace cv;

extern "C" {
JNIEXPORT void JNICALL Java_[your]_[package]_[com]_[class]_[method](JNIEnv* env, jobject thiz, jlong addrGray, jlong addrRgba)
{
//do stuff
}

you can call this method now from your java class:

public native void method(long matAddrGr, long matAddrRgba);

这篇关于从Java类containg的Andr​​oid类错误创建C头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆