Base64编码正在成为图像的一部分

Base64 encode is becoming a piece of the image

我正在尝试从图库中获取图像并将其发送到服务器。
我确实得到了一个 base64 编码的字符串,但它是一条细线,而不是整个图像。

比如我用Motobit解码this random image.得到的base64字符串 工作正常。但是我从我的应用程序获得的相同图像的编码字符串确实更小,当你转换成图像时它变成 this.

这是我的代码:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_profile);


    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    switch(requestCode) {
        case SELECT_PHOTO:
            if(resultCode == RESULT_OK){
                try {
                    Uri selectedImage = imageReturnedIntent.getData();

                    String imageStream = getRealPathFromURI(context, selectedImage);
                    Bitmap bitmap = BitmapFactory.decodeFile(imageStream);

                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
                    byte[] byteArray = byteArrayOutputStream .toByteArray();
                    String encodedString = Base64.encodeToString(byteArray, Base64.DEFAULT);

                    Log.e(LOG_TAG, encodedString);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
    }
}

public String getRealPathFromURI(Context context, Uri contentUri) {
    Cursor cursor = null;
    try {
        String[] proj = { MediaStore.Images.Media.DATA };
        cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}



是什么让我的 encodedString 变成了图像的一部分?谢谢!

也许字符串是正确的,但 Log 方法有字符限制。