2016-01-29 34 views
0

image.c沒有發現本機方法:rabta.pk.chatthahehehe.AndroidUtilities.loadBitmap

JNIEXPORT void Java_rabta_pk_chatthahehehe_AndroidUtilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jobject bitmap, int scale, int width, int height, int stride) { 

    AndroidBitmapInfo info; 
    int i; 

    if ((i = AndroidBitmap_getInfo(env, bitmap, &info)) >= 0) { 
     char *fileName = (*env)->GetStringUTFChars(env, path, NULL); 
     FILE *infile; 

     if ((infile = fopen(fileName, "rb"))) { 
      struct my_error_mgr jerr; 
      struct jpeg_decompress_struct cinfo; 

      cinfo.err = jpeg_std_error(&jerr.pub); 
      jerr.pub.error_exit = my_error_exit; 

      if (!setjmp(jerr.setjmp_buffer)) { 
       jpeg_create_decompress(&cinfo); 
       jpeg_stdio_src(&cinfo, infile); 

       jpeg_read_header(&cinfo, TRUE); 

       cinfo.scale_denom = scale; 
       cinfo.scale_num = 1; 

       jpeg_start_decompress(&cinfo); 
       int row_stride = cinfo.output_width * cinfo.output_components; 
       JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) & cinfo, JPOOL_IMAGE, 
                   row_stride, 1); 

       unsigned char *pixels; 
       if ((i = AndroidBitmap_lockPixels(env, bitmap, &pixels)) >= 0) { 
        int rowCount = min(cinfo.output_height, height); 
        int colCount = min(cinfo.output_width, width); 

        while (cinfo.output_scanline < rowCount) { 
         jpeg_read_scanlines(&cinfo, buffer, 1); 

         //if (info.format == ANDROID_BITMAP_FORMAT_RGBA_8888) { 
         if (cinfo.out_color_space == JCS_GRAYSCALE) { 
          for (i = 0; i < colCount; i++) { 
           float alpha = buffer[0][i]/255.0f; 
           pixels[i * 4] *= alpha; 
           pixels[i * 4 + 1] *= alpha; 
           pixels[i * 4 + 2] *= alpha; 
           pixels[i * 4 + 3] = buffer[0][i]; 
          } 
         } else { 
          int c = 0; 
          for (i = 0; i < colCount; i++) { 
           pixels[i * 4] = buffer[0][i * 3]; 
           pixels[i * 4 + 1] = buffer[0][i * 3 + 1]; 
           pixels[i * 4 + 2] = buffer[0][i * 3 + 2]; 
           pixels[i * 4 + 3] = 255; 
           c += 4; 
          } 
         } 
         //} else if (info.format == ANDROID_BITMAP_FORMAT_RGB_565) { 

         //} 

         pixels += stride; 
        } 

        AndroidBitmap_unlockPixels(env, bitmap); 
       } else { 
        throwException(env, "AndroidBitmap_lockPixels() failed ! error=%d", i); 
       } 

       jpeg_finish_decompress(&cinfo); 
      } else { 
       throwException(env, "the JPEG code has signaled an error"); 
      } 

      jpeg_destroy_decompress(&cinfo); 
      fclose(infile); 
     } else { 
      throwException(env, "can't open %s", fileName); 
     } 

     (*env)->ReleaseStringUTFChars(env, path, fileName); 
    } else { 
     throwException(env, "AndroidBitmap_getInfo() failed ! error=%d", i); 
    } 

nativeloader.java

private final static int LIB_VERSION = 4; 
    private final static String LIB_NAME = "chat." + LIB_VERSION; 
    . 
    . 
    . 
    . 
    . 

     try { 
      System.loadLibrary(LIB_NAME); 
      nativeLoaded = true; 
     } catch (Error e) { 
      Log.e(Constants.TAG, e.getMessage()); 
     } 

logcat的

01-29 11:15:34.747 3628-3628/rabta.pk.chatthahehehe E/cutils: to chown(/mnt/shell/emulated/0, 0, 0) 
01-29 11:15:34.747 3628-3628/rabta.pk.chatthahehehe E/cutils: to chown(/mnt/shell/emulated/obb, 0, 0) 
01-29 11:15:34.748 3628-3628/rabta.pk.chatthahehehe E/cutils: to chown(/storage/emulated/0/Android, 0, 0) 
01-29 11:15:34.748 3628-3628/rabta.pk.chatthahehehe E/cutils: to chown(/storage/emulated/0/Android/obb, 0, 0) 
01-29 11:15:35.057 3628-3628/rabta.pk.chatthahehehe E/linker: load_library(linker.cpp:759): library "libmaliinstr.so" not found 
01-29 11:15:36.348 3628-3779/rabta.pk.chatthahehehe E/TAG: Native method not found: rabta.pk.chatthahehehe.AndroidUtilities.loadBitmap:(Ljava/lang/String;Landroid/graphics/Bitmap;IIII)V 
01-29 11:15:36.384 3628-3780/rabta.pk.chatthahehehe E/TAG: Native method not found: rabta.pk.chatthahehehe.AndroidUtilities.loadBitmap:(Ljava/lang/String;Landroid/graphics/Bitmap;IIII)V 
01-29 11:15:36.411 3628-3784/rabta.pk.chatthahehehe E/TAG: Native method not found: rabta.pk.chatthahehehe.AndroidUtilities.loadBitmap:(Ljava/lang/String;Landroid/graphics/Bitmap;IIII)V 
01-29 11:15:36.427 3628-3786/rabta.pk.chatthahehehe E/TAG: Native method not found: rabta.pk.chatthahehehe.AndroidUtilities.loadBitmap:(Ljava/lang/String;Landroid/graphics/Bitmap;IIII)V 
01-29 11:15:37.527 3628-3851/rabta.pk.chatthahehehe E/TAG: Native method not found: rabta.pk.chatthahehehe.AndroidUtilities.loadBitmap:(Ljava/lang/String;Landroid/graphics/Bitmap;IIII)V 
01-29 11:15:37.528 3628-3850/rabta.pk.chatthahehehe E/TAG: Native method not found: rabta.pk.chatthahehehe.AndroidUtilities.loadBitmap:(Ljava/lang/String;Landroid/graphics/Bitmap;IIII)V 
+0

需要一些緊急的幫助..因爲我困在這裏,連續3天.. –

+0

我願意給整個代碼,如果有人能幫助我。 –

+0

你不應該提供「給出整個代碼」,而應該在你的問題中描述你想要做什麼以及出錯的方式。目前,這只是一個帶有錯誤信息的代碼轉儲,希望有人爲您進行調試。 –

回答

0

您必須聲明你的方法在Java方面是這樣的:

class AndroidUtilities 
{ 
    private static native void loadBitmap(String path, android.graphics.Bitmap bitmap, int scale, int width, int height, int stride); 

} 
+0

已經聲明爲: private static native void loadBitmap(String path,Bitmap bitmap,int scale,int width,int height,int stride); –

+0

你介意看我的代碼嗎? @Tomasz –

+0

好吧,請發給我 –