您现在的位置是:首页 > 文章详情

javah生成头文件

日期:2018-04-15点击:304

编写native方法,如:

package com.example.renzhenming.appmarket.ui.selectimage; import android.graphics.Bitmap; public class ImageUtil { static { System.loadLibrary("jpeg"); System.loadLibrary("compressimg"); } /** * 图片压缩 * @param quality 压缩的质量 * @param fileName 压缩后的路径 */ public static void compressImage(Bitmap bitmap,int quality, String fileName){ compressBitmap(bitmap,quality,fileName); } /** * NDK方法加载图片 * @param quality 压缩的质量 * @param fileName 压缩后的路径 * @return */ public native static int compressBitmap(Bitmap bitmap,int quality, String fileName); /*public static Bitmap decodeFile(String path) { int finalWidth = 800; // 先获取宽度 BitmapFactory.Options options = new BitmapFactory.Options(); // 不加载图片到内存只拿宽高 options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path,options); int bitmapWidth = options.outWidth; int inSampleSize = 1; if(bitmapWidth>finalWidth){ inSampleSize = bitmapWidth/finalWidth; } options.inSampleSize = inSampleSize; options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(path,options); }*/ } 

cmd进入build/intermediates/classes/debug文件目录下,输入如下命令

C:\Users\renzhenming\Desktop\appdemo\AppMarketDemo\app\build\intermediates\classes\debug>javah -classpath D:\application\java\sdk\platforms\android-26\android.jar;. -jni com.example.renzhenming.appmarket.ui.selectimage.ImageUtil 

其中的-classpath作用是引入安卓类库中的类,因为很明显在上边我们的例子中使用了Android中的bitmap类,如果我们不加-classpath的话,就会报错
错误: 找不到类android.graphics.Bitmap。(如果没有使用的话不需要加)
注意后边的分号和点必须加,否则无法找到


img_2ed8a1932dad5eb62b09cc4375aeeab3.png
图片.png

编写完成后make project 一下,会在文件夹下生成.h文件(不make也许也可以)


img_1b32f11d7df9397639c0674b3943cda4.png
图片.png

这样我们就获取到头文件了,可以进行c语言编程了
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class com_example_renzhenming_appmarket_ui_selectimage_ImageUtil */ #ifndef _Included_com_example_renzhenming_appmarket_ui_selectimage_ImageUtil #define _Included_com_example_renzhenming_appmarket_ui_selectimage_ImageUtil #ifdef __cplusplus extern "C" { #endif /* * Class: com_example_renzhenming_appmarket_ui_selectimage_ImageUtil * Method: compressBitmap * Signature: (Landroid/graphics/Bitmap;ILjava/lang/String;)I */ JNIEXPORT jint JNICALL Java_com_example_renzhenming_appmarket_ui_selectimage_ImageUtil_compressBitmap (JNIEnv *, jclass, jobject, jint, jstring); #ifdef __cplusplus } #endif #endif 
原文链接:https://yq.aliyun.com/articles/657348
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章