0

I'm uploading an image to server, before doing so, I'm loading the image to bitmap, where i'm getting out of memory exception and my App crashes. Can i remove the exception without resizing the image. Any solution will help. Here i'm not setting the image to any imageView or drawable I'm only uploadint the image to a server.

@Override
public  Map<String, DataPart> getByteData() {
Map<String, DataPart> params = new HashMap<>();
Log.e(TAG, "ImageUri--" + uri);
try { myBitmap=
MediaStore.Images.Media.getBitmap(
                        getApplicationContext().getContentResolver(), uri);
long imagename = System.currentTimeMillis();
params.put("file", new DataPart(imagename + ".jpg", getFileDataFromDrawable(myBitmap)));
} catch (FileNotFoundException e) {
Toast.makeText(CameraActivity.this,"TryAgain!!",Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
    }
return params;
}

Actual result =

 myBitmap=
MediaStore.Images.Media.getBitmap(
                        getApplicationContext().getContentResolver(), uri);

is generating the exception. Fatal Exception : java.lang.OutOfMemory Exception

Failed to allocate a 51916812 byte allocation with 16777216 free bytes and 43MB until OOM

Expected result = No error or crash

Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
B.S. Dash
  • 47
  • 7

0 Answers0