javah生成头文件

编写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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值