第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

選擇一個(gè)后裁剪圖像的最佳方式

選擇一個(gè)后裁剪圖像的最佳方式

青春有我 2023-03-09 10:33:45
需要裁剪圖像的最佳方式嘗試了一些方法,但它沒有給我正確裁剪的選項(xiàng),如果你可以請(qǐng)幫我提供示例和裁剪圖像的最佳方法private void selectFile() {    Intent img = new Intent(Intent.ACTION_OPEN_DOCUMENT);    img.setType("image/*");    startActivityForResult(i, 3000);}--- Mohammed --- 裁剪后如何獲取Uri                Uri uri = data.getData();                getContentResolver().takePersistableUriPermission(Objects.requireNonNull(uri), Intent.FLAG_GRANT_READ_URI_PERMISSION);                stickerPack.addSticker(uri, this);            }            finish();            startActivity(getIntent());        }
查看完整描述

1 回答

?
富國滬深

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊

您可以使用默認(rèn)的 android Crop 功能


int PICK_IMAGE_REQUEST = 100;

int PIC_CROP = 1;


void chooseImageFromGallery() {

    if (isPermissionsGranted(Manifest.permission.READ_EXTERNAL_STORAGE)) {

        Intent intent = new Intent(Intent.ACTION_PICK,

                MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);

    } else {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),

                    PICK_IMAGE_REQUEST);

        }

    }

}


 @Override void onRequestPermissionsResult(int requestCode,

        String permissions[], int[] grantResults) {

        super.onRequestPermissionsResult(requestCode, permissions, grantResults)

               if (requestCode == PICK_IMAGE_REQUEST && grantResults.length > 0  && grantResults[0] == PackageManager.PERMISSION_GRANTED ) {

                chooseImageFromGallery()

               }

    }



@Override void onActivityResult(Int requestCode, Int resultCode, Intent data) {

    if (resultCode == Activity.RESULT_OK && requestCode == PICK_IMAGE_REQUEST) {

        Uri imageUri = data?.data

        performCrop(imageUri)

    }else if(resultCode == Activity.RESULT_OK && requestCode == PIC_CROP){

     // get the returned data

    Bundle extras = data.getExtras();

    // get the cropped bitmap

    Bitmap selectedBitmap = extras.getParcelable("data");


    imgView.setImageBitmap(selectedBitmap);

    }

}


private void performCrop(Uri picUri) {

try {

    Intent cropIntent = new Intent("com.android.camera.action.CROP");

    // indicate image type and Uri

    cropIntent.setDataAndType(picUri, "image/*");

    // set crop properties here

    cropIntent.putExtra("crop", true);

    // indicate aspect of desired crop

    cropIntent.putExtra("aspectX", 1);

    cropIntent.putExtra("aspectY", 1);

    // indicate output X and Y

    cropIntent.putExtra("outputX", 128);

    cropIntent.putExtra("outputY", 128);

    // retrieve data on return

    cropIntent.putExtra("return-data", true);

    // start the activity - we handle returning in onActivityResult

    startActivityForResult(cropIntent, PIC_CROP);

}

// respond to users whose devices do not support the crop action

catch (ActivityNotFoundException anfe) {

    // display an error message

    String errorMessage = "Whoops - your device doesn't support the crop action!";

    Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);

    toast.show();

}

}

或者您可以使用任何庫來選擇和裁剪圖像,請(qǐng)檢查這些庫


https://github.com/ArthurHub/Android-Image-Cropper


https://github.com/Yalantis/uCrop


查看完整回答
反對(duì) 回復(fù) 2023-03-09
  • 1 回答
  • 0 關(guān)注
  • 104 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)