I'm trying to send and show image file. I can show and encode/decode image about 50kb (lower than 50kb). But when I try to send/encode image bigger than 100kb I get an error: "java.lang.OutOfMemoryError"
.
Uri selectedImage = intent.getData();
String filePath=MediaOperations.getPath(getApplicationContext(), selectedImage);
if (bmp != null && !bmp.isRecycled()) {
bmp = null;
}
bmp = BitmapFactory.decodeFile(filePath);
I use this codes for getting file path.
I convert bitmap to byte array and byte array to base64string. And I'm sending basese64string to server with socketio. And I am showing bitmap in ImageView. But base64 encoding and imageview doesn't work when file is larger than 50kb. How can I solve this problem?
I tried android:largeHeap="true"
but did not solve my problem
Thanks in advance
UDATE
bitmap to byteArray:
public static byte[] getBytes(Bitmap bitmap) {
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, stream);
return stream.toByteArray();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} }
byte array to base64String:
public static String getBase64(byte[] array){
try {
return Base64.encodeToString(array, Base64.DEFAULT);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} }
UPDATE 2:
Window is full: requested allocation 15120804 bytes, free space 2096642 bytes, window size 2097152 bytes <br></br>
java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
ERROR_LOG:
03-21 11:47:24.116: E/dalvikvm-heap(2084): Out of memory on a 30241618-byte allocation.
03-21 11:47:24.120: I/dalvikvm(2084): "main" prio=5 tid=1 RUNNABLE
03-21 11:47:24.124: I/dalvikvm(2084): | group="main" sCount=0 dsCount=0 obj=0xa4bca480 self=0xb8a84bd0
03-21 11:47:24.128: I/dalvikvm(2084): | sysTid=2084 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=-1216913376
03-21 11:47:24.132: I/dalvikvm(2084): | state=R schedstat=( 9832259071 3939135544 5574 ) utm=726 stm=256 core=0
03-21 11:47:24.136: I/dalvikvm(2084): at java.lang.String.<init>(String.java:~365)
03-21 11:47:24.140: I/dalvikvm(2084): at java.lang.String.<init>(String.java:228)
03-21 11:47:24.144: I/dalvikvm(2084): at android.util.Base64.encodeToString(Base64.java:456)