android - 如何将图像高质量快速上传到服务器
问题描述
实际上我正在尝试将图像上传到具有出色质量的服务器。目前我正在将位图数组转换为base64
字符串arrayList
,然后将其发送到服务器socket.io
。但问题是当我试图提高位图base64
转换的质量时花费了很多时间,而且效率很低。即使花了这么多时间,我在服务器中得到的图像质量也很差。所以有人可以帮我解决这个问题并提高上传效率吗?
代码:
public ArrayList<String> convert(ArrayList<Bitmap> bitmap){
ArrayList<String> pics=new ArrayList<>();
for(int i=0;i<bitmap.size();i++){
pics.add(getStringImage(bitmap.get(i)));
}
return pics;
}
public static String getStringImage(Bitmap bmp){
//I've givent maxSize as 500
int outWidth;
int outHeight;
int inWidth = bmp.getWidth();
int inHeight = bmp.getHeight();
if(inWidth > inHeight){
outWidth = maxSize;
outHeight = (inHeight * maxSize) / inWidth;
} else {
outHeight = maxSize;
outWidth = (inWidth * maxSize) / inHeight;
}
Bitmap new_bitmap = Bitmap.createScaledBitmap(bmp, outWidth, outHeight, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new_bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
// Sending to server
final JSONObject obji=new JSONObject();
try {
//bit is arraylist of bitmap
obji.put("uploads_username",username);
obji.put("uploads",convert(bit));
socket.emit("data",obji);
}catch(Exception e){
}
解决方案
推荐阅读
- javascript - 在 forloop 中使用 .push 的函数不断地为数组赋值
- node.js - 在 AWS Lambda 上发出 https 请求
- alexa - Alexa 接受内置插槽类型的错误值
- mysql - 从外部表中按日期和 id 对 COUNT 进行分组
- r - 返回字符串的开头,最多包含两个字符中的任何一个
- azure - 使用 Azure Data Lake gen2 列出 blob 的问题
- python - 当 python 在 SQL Server 代理中作为作业运行时出现 ModuleNotFoundError
- scala - 如何创建宏以在案例类中创建 val 列表?
- primefaces - 如何制作可关闭的 p:selectOneButton?
- xml - XSLT 中子字符串的复杂使用