Java Base64编码在Android中花费的时间太长

Java Base64编码在Android中花费的时间太长,java,android,base64,Java,Android,Base64,我正在用相机拍一张照片。我将文件保存在公共照片目录中,并将Uri保存到该文件中 我想将图像保存在Base64String中,然后将其放在HashMap中,然后将其放在XML文件中 protected Void doInBackground(Void...voids) { options.inJustDecodeBounds = false; //Bitmap bmp = BitmapFactory.decodeFile(imageFilePath,options)

我正在用相机拍一张照片。我将文件保存在公共照片目录中,并将
Uri
保存到该文件中

我想将图像保存在
Base64
String
中,然后将其放在
HashMap
中,然后将其放在XML文件中

protected Void doInBackground(Void...voids) {
        options.inJustDecodeBounds = false;
        //Bitmap bmp = BitmapFactory.decodeFile(imageFilePath,options);
        InputStream in = null;
        try {
            in = getContentResolver().openInputStream(Uri.parse(mCurrentPhotoPath));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        options.inSampleSize = 2;
        Bitmap image = BitmapFactory.decodeStream(in,null,options);
        int imgHeight = image.getHeight();
        int imgWidth = image.getWidth();
        while(imgHeight>2000){
            imgHeight = imgHeight / 2;
        }
        while(imgWidth>2000){
            imgWidth = imgWidth / 2;
        }

        Bitmap test = Bitmap.createScaledBitmap(image,imgWidth,imgHeight,false);

        String stest = base64EncodeDecode.encodeToBase64(test);


        items.put("image",base64EncodeDecode.encodeToBase64(test);
        return null;
}
Base64
编码时间太长。 encodeToBase64方法

public String encodeToBase64(Bitmap image) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();

    return Base64.encodeToString(b, Base64.DEFAULT);
}
你能告诉我编码时是否做错了什么吗

我希望我的问题很清楚


亲切的问候

如果您得到
!!!活页夹事务失败错误可能是因为您要将大量数据传递给另一个
活动
,因此您可以发送的数据量是有限制的。尝试将图像压缩到50%或30%
image.compress(Bitmap.CompressFormat.JPEG,50,baos)

多长时间是“太长”,字节数组有多大?您是如何诊断出是base64编码占用了时间而不是(比如)压缩的?为什么要多次编码
String stest=Base64EncodeCode.encodeToBase64(测试);taskItems.put(“image”,base64EncodeDecode.encodeToBase64(BitmapFactory.decodeStream(in,null,options))
第一个编码字符串用于已完成采样的位图。采样后,你想对真正的位图进行编码吗?是的,我看到了,所以我编辑了代码!谢谢你的建议。我不知道为什么,但是在调试时编码需要很长时间。跑步是“正常的”。表示您没有注意到任何编码。我现在得到的是
!!!活页夹事务失败当我将数据传递到其他
活动时。