I want to store byte array of data in to .jpg file by using JNI in android. i use following code, it will store the byte array data but .jpg file is not open or it will show error while opening the file in phone gallery.
Here bmpArray : byte array filePath : sdcard directory+ filename
void Java_com_appsforbb_businesscardreader_ImageUtility_setNativeBitmapArray(JNIEnv* env, jclass object,jbyteArray bmpArray,jstring filePath)
{
jbyte* bmp= env->GetByteArrayElements(bmpArray, 0);
jsize length = env->GetArrayLength(bmpArray);
jbyteArray arr = env->NewByteArray(length);
const char* path = env->GetStringUTFChars(filePath, 0);
FILE* file = fopen( path, "w+" );
fwrite(bmpArray, 1, length, file );
fflush(file);
fclose(file);
LOGI("Byte array stored..");
}
yes i got the solution replace the parameter bmpArray into bmp
i.e
void Java_com_appsforbb_businesscardreader_ImageUtility_setNativeBitmapArray(JNIEnv* env, jclass object,jbyteArray bmpArray,jstring filePath)
{
jbyte* bmp= env->GetByteArrayElements(bmpArray, 0);
jsize length = env->GetArrayLength(bmpArray);
const char* path = env->GetStringUTFChars(filePath, 0);
FILE* file = fopen( path, "w+" );
fwrite(bmp, 1, length, file );
fflush(file);
fclose(file);
free(bmp);
free(file);
LOGI("---------->byte array stored..");
}