2

我有一个允许用户提交表单的 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);
4

1 回答 1

3

您可以使用线程并行运行上传任务,这可以加快上传速度。Android 开发人员指南在Threads 和 process上有很好的文档(带有示例代码)。

于 2012-06-16T23:10:21.873 回答