我有一个允许用户提交表单的 android 应用程序,现在这个表单可以有 9 个位图(MAX)。现在我的代码运行良好,但是上传图片需要很长时间。有没有更好的上传图片的方法??
我的代码:
Iterator<String> it = car_images.iterator();
int i = 0;
while (it.hasNext()) {
String imagepath = it.next();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Bitmap b = BitmapFactory.decodeFile(imagepath);
b.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
entity.addPart("image_" + i, new ByteArrayBody(data,
"myImage.jpg"));
Log.d("image loaded", "image_" + i);
++i;
}
put.setEntity(entity);
HttpResponse repsone = client.execute(put);