android base64 outofmemoryerror,android - Throwing OutOfMemory Error(Byte to Base64) - Stack Overflo...

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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值