簡體   English   中英

壓縮選定的圖像文件/從相機拍攝

[英]compressing selected image file/taken from camera

試圖讓用戶添加個人資料圖片,但我想在將圖像文件發送到服務器之前對其進行壓縮。

我怎樣才能壓縮:

文件 imageFile = new File(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)

很想得到一些建議,在此先感謝。

檢查這個

Uri selectedImage = imageReturnedIntent.getData();

InputStream imageStream = null;
try {
    imageStream = getContentResolver().openInputStream(
            selectedImage);
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

Bitmap bmp = BitmapFactory.decodeStream(imageStream);

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
try {
    stream.close();
    stream = null;
} catch (IOException e) {

    e.printStackTrace();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM