38

画像のトリミングをしたいのですが、かなり便利なものを見つけましたが、どういうわけか、選択されていない領域を暗くするのが足りないようなので、誰か方法を知っていますか? または私を正しい方向に導きますか?私が見つけたオンラインチュートリアルは、選択した領域を暗くすることを示していますが、それを使用するとそうではありません。私の英語力の悪さに感謝し、申し訳ありません。

私が使用するチュートリアルへのリンク。

画像の切り抜きチュートリアル 1

画像の切り抜きチュートリアル 2

このようなものにしたいです。

こんなものであってほしい

editButton.setOnClickListener(new Button.OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent goEdit;
            goEdit = new Intent(PreviewActivity.this, CropImage.class);
            goEdit.putExtra("image-path", path);
            goEdit.putExtra("scale", true);
            goEdit.putExtra("fileName", nameFromPath);
            //finish();
            checkEdit = true;
            startActivityForResult(goEdit,0);

        }
});

EDIT このボタンリスナーを使用して、クラスの CropImage アクティビティを呼び出して、cropImage ファイルを呼び出します。これは Android 内のクロップ機能ではなくカスタム インテントですが、すべてのバージョンをサポートするようにそのコピーだと思いますが、それを呼び出すと、選択した領域が明るくならず、どこに問題があるのか​​わかりません。ありがとうこれは私が使用しているライブラリですdroid4youクロップ画像

4

4 に答える 4

53

デフォルトのAndroidクロップ機能を使用できますか?

これが私のコードです

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();
    }
}

宣言する:

final int PIC_CROP = 1;

上部に。

onActivity結果メソッドで、次のコードを記述します。

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

    if (requestCode == PIC_CROP) {
        if (data != null) {
            // get the returned data
            Bundle extras = data.getExtras();
            // get the cropped bitmap
            Bitmap selectedBitmap = extras.getParcelable("data");

            imgView.setImageBitmap(selectedBitmap);
        }
    }
}

実装は非常に簡単で、暗い領域も表示されます。

于 2013-03-06T04:36:58.570 に答える
2

とてもクールなライブラリを見つけたので、これを試してみてください。これは本当にスムーズで使いやすいです。

https://github.com/TakuSemba/CropMe

于 2017-09-13T14:43:03.690 に答える
1

あなたの調子が良いといいのですが。私のコードを使用して画像を切り取ることができます。クラスを作成し、このクラスを自分のXMlおよびjavaクラスに使用するだけです。 画像をトリミングします。選択した画像を円や正方形にトリミングして、多くのオプションを作成できます。これはあなたにとって完全に管理可能であり、あなたに応じて変更できるためです.

仕事を楽しんでください:)

于 2016-02-15T06:14:51.350 に答える