android - JNI method to return bitmap from file path -
below code byte[] specified in parameters want bitmap path represent not byte array don't have convert bitmap in java.
jniexport jbytearray jnicall java_com_lightbox_android_photoprocessing_photoprocessing_getfile(jnienv *env, jobject thisobj,jstring string) { char * path; path = (*env)->getstringutfchars( env, string , null ) ; char* buffer = 0; long length; file * f = fopen (path,"r"); //was "rb" if (f) { fseek (f, 0, seek_end); length = ftell (f); fseek (f, 0, seek_set); buffer = (char*)malloc ((length+1)*sizeof(char)); if (buffer) { fread (buffer, sizeof(char), length, f); } fclose (f); } buffer[length+1] = '\0'; int size = length+1; jbytearray array = (*env)->newbytearray(env, size); (*env)->setbytearrayregion(env, array, 0, size,buffer); free(buffer); return array; }
Comments
Post a Comment