I have an database, And I have some large images to convert it to base64.
And when I'm saving it to database, I received this error.
11-17 11:56:03.359 11549-11620/? E/art: Throwing OutOfMemoryError "Failed to allocate a 63489036 byte allocation with 16777216 free bytes and 47MB until OOM"
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: FATAL EXCEPTION: Thread-792
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: Process: com.juandirection, PID: 11549
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 63489036 byte allocation with 16777216 free bytes and 47MB until OOM
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:635)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:611)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:649)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at com.juandirection.Review$9.getParams(Review.java:206)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at com.android.volley.Request.getBody(Request.java:468)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:253)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:227)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:107)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97)
11-17 11:56:03.359 11549-11620/? E/AndroidRuntime: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)
My image is around 6MB.
Some are around just KB. Kb images works fine but when i upload with 6mb image size, i got that error.
@Override
protected Map getParams() {
Map parameters = new HashMap();
//String filepath = "/storage/emulated/0/Pictures/20150426_085939.jpg";
String filepath = Global.SELECTED_IMAGES.get(valueThisIteration);
String newFilePath = filepath.substring(7,filepath.length());
File imagefile = new File(newFilePath);
FileInputStream fis = null;
try {
fis = new FileInputStream(imagefile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bm = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 70 , baos);
byte[] b = baos.toByteArray();
String encImage = Base64.encodeToString(b, Base64.DEFAULT);
parameters.put("latitude", Global.lat);
parameters.put("imagepath", encImage);
return parameters;
}