image - How to tackle OutOfMemoryError -
when try load images phone memmory out of memory errorjava/lang/outofmemoryerror or nativedecodeimage . images in phone memory of 12kd , while others around 589kb or 600kb. small sized images fetched list when comes larger sized images thrown oom error..??
this code
fileconnection finalconnection; try { fc.close(); finalconnection = (fileconnection) connector.open(path, connector.read_write); if(finalconnection.exists()) { inputstream fis = finalconnection.openinputstream(); long overallsize = finalconnection.filesize(); int length = 0; byte[] imagedata = new byte[0]; while (length < overallsize) { byte[] data = new byte[chunk_size]; int readamount = fis.read(data, 0, chunk_size); byte[] newimagedata = new byte[imagedata.length + chunk_size]; system.arraycopy(imagedata, 0, newimagedata, 0, length); system.arraycopy(data, 0, newimagedata, length, readamount); imagedata = newimagedata; length += readamount; } fis.close(); finalconnection.close(); system.out.println("length " + length); if (length > 0) { image = image.createimage(imagedata, 0, length); } } else { system.out.println("no path image"); } } catch (exception e) { system.out.println("image.createimage(imagedata, 0, length) " +e.tostring()); } catch(error e) { system.out.println("image.createimage " + e); }
the point error @
image = image.createimage(imagedata, 0, length);
does have idea this. stuck thing few days. working on s40 devices nokia 311. netbeans midp 2.0
the clue in exception... images opening large hold in memory. bear in mind compressed size of image not indicate whether can held or not, it's number of pixels.
if it's big there's not can do... if want display image on screen need processing on first shrink it, before can load in memory.
Comments
Post a Comment