Android 向Web服务器发送图像时发生OutOfMemoryException
因此,要将图像发送到web服务器,我需要将其编码到base64,然后在服务器端进行解码 这就是我所关注的 但是我得到了OutOfMemoryException,在这行代码中:Android 向Web服务器发送图像时发生OutOfMemoryException,android,base64,out-of-memory,Android,Base64,Out Of Memory,因此,要将图像发送到web服务器,我需要将其编码到base64,然后在服务器端进行解码 这就是我所关注的 但是我得到了OutOfMemoryException,在这行代码中: httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 图像大小为1mb。那么,有没有其他方法可以做到这一点 我读到: 建议使用多路径。但是我到底在哪里可以找到这些图书馆呢?因为其中一个链接已断开 代码: Uri selectedImageUri =
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
图像大小为1mb。那么,有没有其他方法可以做到这一点
我读到:
建议使用多路径。但是我到底在哪里可以找到这些图书馆呢?因为其中一个链接已断开
代码:
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
try {
File imageFile = new File(selectedImagePath);
Bitmap bitmap = BitmapFactory.decodeFile(imageFile
.getAbsolutePath());
setImage.setImageBitmap(bitmap);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
base64code = Base64.encodeToString(b, Base64.DEFAULT);
} catch (Exception e) {
e.printStackTrace();
}
可能有一种方法是降低质量。但是如果我将其设置为20或30,并且图像已经是低质量的1(取自低端设备)。我可能会得到质量不好的图像
做一些类似于检查尺寸和降低质量的事情。我认为这不是个好主意
谢谢使用多端口将图像上载到服务器是一个不错的选择 多端口库下载: 希望对你有帮助 谢谢。看看这个,我可以使用多端口发送1-2MB文件吗?