首先创建java层对象
package jp.co.ricoh.advop.mini.idcard;/** * Created by tangzhongliang on 9/16/2016. */public class CardInfo { int positionX ; int positionY ; String path; int scale; public CardInfo(int positionX, int positionY, String path,int scale) { this.positionX = positionX; this.positionY = positionY; this.path = path; this.scale = scale; } @Override public String toString() { return String.format("start %d,%d,%s,%d",positionX,positionY,path,scale); }}
将CardInfo数组传入jni中,在Native层中通过反射的方式访问CardInfo信息
JNIEXPORT jint JNICALL Java_jp_co_ricoh_advop_mini_idcard_ImageHandle_combinecard(JNIEnv * env, jobject obj,jstring dstString,jint width,jint height,jobjectArray objarray){ LOGD("combine card"); jsize len = env->GetArrayLength(objarray); int ow = (int)width; int oh = (int)height; Mat newMat = Mat(Size(ow,oh),CV_8UC3,Scalar(255,255,255)); for(int i = 0;iGetObjectArrayElement(objarray,(jsize)i); jclass cls = env->GetObjectClass(cardinfo); jfieldID fid = env->GetFieldID(cls,"positionX","I"); int x = (int)env->GetIntField(cardinfo,fid); fid = env->GetFieldID(cls,"positionY","I"); int y = (int)env->GetIntField(cardinfo,fid); fid = env->GetFieldID(cls,"path","Ljava/lang/String;"); jstring jstr = (jstring)env->GetObjectField(cardinfo,fid); char* path = jstring2string(env,jstr); fid = env->GetFieldID(cls,"scale","I"); int scale = (int)env->GetIntField(cardinfo,fid); //resize Mat logo = imread(path,-1); resize(logo,logo,Size(logo.cols*scale,logo.rows*scale)); LOGD("%d,%d,%d",ow,oh,scale); if(mixImage(newMat,logo,x,y)==-1){ return -1; } } char* dstPath = jstring2string(env,dstString); imwrite(dstPath,newMat); LOGD("complete"); return 0; }