Android NDK. Not a JPEG image: starts with 0x00 0x00 -


i want use jpeg images in android ndk application. downloaded libjpeg9 , compiled static library. load image apk libzip , when begin reading header of image following error: "not jpeg file: starts 0x00 0x00". same error occured when launch application in emulator , real device well. type in terminal command check file: "file myjpeg.jpg" , following message: "myjpeg.jpg: jpeg image data, jfif standard 1.01" file valid. moreover, if load same image file jpeg_stdio_src function in macos app success. part of code responsible loading jpeg files in android:

zip * apk = zip_open(apk_path.c_str(), 0, null); if (!apk)     return false;  zip_file * fp = zip_fopen(apk, path.c_str(), 0); if (!fp) {     zip_close(apk);     return false; }  jsamparray buffer; int stride;  jpeg_error_handler jerr; jpeg_decompress_struct cinfo;  cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = jpeg_error_exit; jerr.pub.output_message = jpeg_error_msg;  unsigned char * imagedata = null; if (setjmp(jerr.setjmp_buffer)) {     jpeg_destroy_decompress(&cinfo);     zip_fclose(fp);     zip_close(apk);     if (imagedata) free(imagedata);     return false; }  struct zip_stat st; zip_stat_init(&st); zip_stat(apk, path.c_str(), 0, &st); if (st.size <= 0) {     zip_fclose(fp);     zip_close(apk);     return false; }  imagedata = (unsigned char*)malloc(sizeof(unsigned char) * st.size); memset(imagedata, 0x0, sizeof(unsigned char) * st.size);  jpeg_create_decompress(&cinfo); jpeg_mem_src(&cinfo, imagedata, st.size);  jpeg_read_header(&cinfo, true); jpeg_start_decompress(&cinfo); stride = cinfo.output_width * cinfo.output_components; buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, jpool_image, stride, 1);  jpg->width = cinfo.image_width; jpg->height = cinfo.image_height; jpg->colormode = cinfo.output_components;  log("loaded: " + path + " width: " + stringutils::inttostr(jpg->width) + " height: " +             stringutils::inttostr(jpg->height) + " color mode: " +             stringutils::inttostr(jpg->colormode));  // read jpeg image... 

how can read correct data file? suppose file isn't loaded buffer jpeg_mem_src don't know reasons. in advance.

it looks aren't telling library image data is. imagedata set 0's passed library.

jpeg_mem_src tells library "decoded jpeg data" located. need pass in pointer data.

it looks retrieving apk, try passing pointer data jpeg_mem_src instead.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -