Changeset 712


Ignore:
Timestamp:
Mar 1, 2011, 1:13:28 AM (9 years ago)
Author:
sam
Message:

android: Add a method for PNG loading. Highly hackish for now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/androidapp.cpp

    r710 r712  
    3535}
    3636
     37static void TestPng(JNIEnv *env)
     38{
     39    jclass cls = env->FindClass("org/zoy/LolEngine/LolActivity");
     40    jmethodID mid;
     41
     42    /* Open image from resources */
     43    mid = env->GetStaticMethodID(cls, "openImage", "(Ljava/lang/String;)V");
     44    jstring name = env->NewStringUTF("ascii");
     45    env->CallStaticVoidMethod(cls, mid, name);
     46    env->DeleteLocalRef(name);
     47
     48    /* Get image dimensions */
     49    mid = env->GetStaticMethodID(cls, "getWidth", "()I");
     50    jint w = env->CallStaticIntMethod(cls, mid);
     51    mid = env->GetStaticMethodID(cls, "getHeight", "()I");
     52    jint h = env->CallStaticIntMethod(cls, mid);
     53    __android_log_print(ANDROID_LOG_INFO, "LOL", "Loaded PNG %dx%d", w, h);
     54
     55    /* Get pixels */
     56    jintArray arr = env->NewIntArray(w * h * 4);
     57    mid = env->GetStaticMethodID(cls, "getPixels", "([I)V");
     58    env->CallStaticVoidMethod(cls, mid, arr);
     59
     60    /* Do something with the pixels */
     61    jint *data = env->GetIntArrayElements(arr, 0);
     62    __android_log_print(ANDROID_LOG_INFO, "LOL", "pixels %08x %08x %08x %08x",
     63                        (unsigned)data[0], (unsigned)data[1],
     64                        (unsigned)data[2], (unsigned)data[3]);
     65    env->ReleaseIntArrayElements(arr, data, 0);
     66    env->DeleteLocalRef(arr);
     67
     68    /* Free image */
     69    mid = env->GetStaticMethodID(cls, "closeImage", "()V");
     70    env->CallStaticVoidMethod(cls, mid);
     71}
     72
    3773extern "C" void
    3874Java_org_zoy_LolEngine_LolRenderer_nativeResize(JNIEnv* env, jobject thiz,
     
    4177    __android_log_print(ANDROID_LOG_INFO, "LOL", "resize w=%d h=%d", w, h);
    4278    Video::Setup(w, h);
     79
     80    TestPng(env);
    4381}
    4482
Note: See TracChangeset for help on using the changeset viewer.