压缩选择的图像文件/从相机拍摄

时间:2020-06-21 15:44:26

标签: java android

试图让用户添加个人资料图片,但是我想在将图像文件发送到服务器之前对其进行压缩。

我如何压缩:

文件imageFile =新文件(resultUri.getPath());

尝试并搜索,但无法正常工作

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            if (resultCode == RESULT_OK) {
                Uri resultUri = result.getUri();
                btnConfirm.setVisibility(View.VISIBLE);
                btnConfirm.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        File imageFile = new File(resultUri.getPath());

                        progressDialog.show();
                        AndroidNetworking.upload("https://myweb.com/uploadImg.php")
                                .addMultipartFile("image", imageFile)

希望得到一些建议,谢谢。

1 个答案:

答案 0 :(得分:0)

检查

catch (error) {
    if (error.type === 'UnauthenticatedError') {
        throw new functions.https.HttpsError('unauthenticated', error.message);
    } else if (error.type === 'NotAnAdminError' || error.type === 'InvalidRoleError') {
        throw new functions.https.HttpsError('failed-precondition', error.message);
    } else if (error.code === 'auth/email-already-exists') {          
        //return the error code here
    } else {
         throw new functions.https.HttpsError('internal', error.type); 
    }
}