本帖最后由 wings4ever 于 2011-06-01 10:21:17 编辑

解决方案 »

  1.   

    #include "w4e/ResourceMgr.h"
    #include "ximage.h"
    #include <linux/bitmap.h>ResourceMgr* ResourceMgr::Instance()
    {
    static ResourceMgr instance;
    return &instance;
    }ResourceMgr::ResourceMgr()
    {

    }
    bool ResourceMgr::Setjobj(JNIEnv* env,jobject obj)
    {
    jResMgrObj=obj;
    return TRUE;
    }char * ResourceMgr::GetBmp(JNIEnv* env,jobject obj)
    {
    jclass jResMgr;
    jmethodID jID;
    LOGI("ready to find java class");
    jResMgr=env->FindClass("com/test/w4e/w4e");
    if (jResMgr==NULL)
    {
    LOGI("java class not found");
    return NULL;
    }
    else
    {
    LOGI("java class found");
    jfieldID fid = env->GetStaticFieldID(jResMgr, "res","Landroid/content/res/Resources;");
    if (fid!=NULL)
    {
    jobject res = env->GetStaticObjectField(jResMgr, fid);
    if (res==NULL)
    {
    LOGI("NULL RES");
    }
    else
    {
    LOGI("get res successed");
    jID=env->GetMethodID(jResMgr,"PostBmptoJni","(Landroid/content/res/Resources;I)Z");
    if (jID!=0)
    {
    LOGI("java method found ID=%d",jID);
    jint ji=0x7f020003;
    jobject ob=env->AllocObject(jResMgr);
    LOGI("ready to call java method");
    jboolean bl=env->CallBooleanMethod(ob,jID,res,ji);
    LOGI("call java method complete");
    }
    else
    {
    LOGI("java methord not found");
    }
    }
    }
    }
    return NULL;
    }
    public boolean PostBmptoJni(Resources res1,int ID){
    Log.i("w4e","this is from MyResMgr of Java ID="+ID);
    Bitmap bmp=null;
    if (res1==null)
    {
    Log.i("w4e","null res pointer");
    }
    else
    {
    bmp=BitmapFactory.decodeResource(res1,ID);
    Log.i("w4e","not null res pointer");
    }
        if (bmp!=null)
        {
         Log.i("w4e","get bmp1 successed");
         int w=bmp.getWidth();
        int h=bmp.getHeight();
        String jstr=bmp.toString();
        int sz=jstr.length();
        }
        else
        {
         Log.i("w4e","empty bmp1");
        }
        return true;
    }public static Resources res;