OOM异常,请问各位大师有什么解决办法?
OOM截图:
private String encode(String path) {
Bitmap bitmap = null;
bitmap = BitmapFactory.decodeFile(path);
//convert to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] src = baos.toByteArray();
StringBuilder sb = new StringBuilder();
int bufsize = 128;
byte[] dst = new byte[bufsize];
int toread = 0;
int totalread = 0; //读取字节
while (totalread < src.length) {
if (src.length - totalread >= bufsize) //剩余大小>bufsize
{
toread = bufsize;
} else {
toread = src.length - totalread;
}
System.arraycopy(src, totalread, dst, 0, toread);
totalread +=toread;
sb.append(android.util.Base64.encodeToString(dst, 0, toread, Base64.DEFAULT));
// Log.v("base64",android.util.Base64.encodeToString(dst, 0, toread, Base64.DEFAULT));
}
//base64 encode
// byte[] encode = android.util.Base64.encode(bytes, Base64.DEFAULT);
//return new String(encode);
return sb.toString();//encode;
}
Bitmap bitmap = BitmapFactory.decodeFile(path);
//convert to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] bytes = baos.toByteArray();
//base64 encode
byte[] encode = Base64.encode(bytes,Base64.DEFAULT);
String encodeString = new String(encode);
http://wiki.jikexueyuan.com/project/android-actual-combat-skills/picture-basesixtyfour-coding-and-decoding.html
http://blog.csdn.net/h7870181/article/details/19971557
http://outofmemory.cn/code-snippet/36105/java-image-base64