请教: JNI下,需要对Android下Paint类中setStyle的进行封装,在本地实现对setStyle的调用。
问题是怎样传入 Paint.Style.STROKE , Paint.Style.FILL , Paint.Style.FILL_AND_STROKE;它们的类型是定义为对象,还是字符串?
- C/C++ code
VOID CVMAndroidDC::SetStyle(int nStyle){ jstring style; //---------存储上述三个参数的变量; switch(nStyle) { case 0: style = CVMAndroidApp::GetInstance()->jar_Text2JString("Paint.Style.STROKE", JNI_FALSE); break; case 1: style = CVMAndroidApp::GetInstance()->jar_Text2JString("Paint.Style.FILL", JNI_FALSE); break; default: style = CVMAndroidApp::GetInstance()->jar_Text2JString("Paint.Style.FILL_AND_STROKE", JNI_FALSE); } static jmethodID jmidSetStyle=NULL; if(jmidSetStyle==NULL) { jclass jclsPaint=m_pJNIEnv->FindClass("android/graphics/Paint"); jmidSetStyle=m_pJNIEnv->GetMethodID(jclsPaint,"setStyle","(Landroid/graphics/Paint/Style;)V"); } m_pJNIEnv->CallVoidMethod(m_jobjPaint,jmidSetStyle,style); //此处传入style存储的三个参数之一}
上面的代码只是我的一点想法,请各位多多指教!!
------解决方案--------------------
看sdk,是个枚举
enum
Paint.Style
The Style specifies if the primitive being drawn is filled, stroked, or both (in the same color).
枚举里面是实实在在的值而不是用变量,因此jni接口里不能通过0,1,2这样的const来判断。最好是自己在java层将枚举转成int,然后再传到jni里
------解决方案--------------------
LOG中却提示GetMethodID: method not found: Landroid/graphics/Paint; setStyle :(Landroid/graphics/Paint/Style;)V
你打错了吧,应该是Android
------解决方案--------------------
Landroid/graphics/Paint$Style
换成这样?