我正在尝试使用以下代码读取图像的字节数组,但它会引发内存不足异常。我已经评论了异常发生的地方。
byte[] bBuffer = new byte[300000]; //
ByteArrayBuffer baf = new ByteArrayBuffer(300000);
int total = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
int read = 0;
while ((dis.read(bBuffer, 0, bBuffer.length)) != -1) {
baos.write(bBuffer, 0, bBuffer.length); // Exception occurs here
Log.d("outputImageBytes", "Reading Image Bytes: " + bBuffer.length + " " + read++ );
}
//baos.flush();
}
catch (Exception e)
{
Log.e("outputImageBytes", "Exception Occured while reading image bytes: " + e.getMessage());
e.getMessage();
}