8

カメラを使用して写真を撮った後、トリミングに com.android.camera.action.CROP を使用していました。

以下は、4.3 より前に動作していた私のコードです。

Intent cropIntent = new Intent("com.android.camera.action.CROP");
                        cropIntent.setType("image/*");
                        cropIntent.putExtra("crop", "true");
                        cropIntent.putExtra("aspectX", 1);
                        cropIntent.putExtra("aspectY", 1);
                        cropIntent.putExtra("outputX", Conf.getInt("IMAGE_WIDTH"));
                        cropIntent.putExtra("outputY", Conf.getInt("IMAGE_HEIGHT"));
                        cropIntent.putExtras(extras);
                        startActivityForResult(cropIntent, CROP_REQUEST_CODE);

しかし、Android の切り抜きアクションでギャラリーに移動するため (ギャラリーはデフォルトで切り抜きであるため)、この切り抜き方法は失敗します (写真はギャラリーに保存されません)。

この問題から抜け出す方法を知っている人はいますか。カメラで撮影した写真でクロップを使用できる場所

4

3 に答える 3

9

以前に尋ねられた同様の質問からの回答をコピーします..

次のようなライブラリを使用することを検討しましたか:

GitHubリンク

com.android.camera.action.CROP は電話によって動作が異なる場合があり、常に利用できるとは限らないため、リリースしようとしている場合はとにかく問題が発生する可能性があります。

アップデート:

上記のライブラリを Android 4.3 でテストしましたが、問題なく動作します。ライブラリをプロジェクトに追加するだけです。

その後、非常によく似た方法でメソッドを記述できます。

private void performCrop(Uri picUri) {
//you have to convert picUri to string and remove the "file://" to work as a path for this library
String path = picUri.toString().replaceAll("file://", "");
try {
    int aspectX = 750;
    int aspectY = 1011;

    Intent intent = new Intent(this, CropImage.class);
    //send the path to CropImage intent to get the photo you have just taken or selected from gallery
    intent.putExtra(CropImage.IMAGE_PATH, path);

    intent.putExtra(CropImage.SCALE, true);

    intent.putExtra("aspectX", aspectX);
    intent.putExtra("aspectY", aspectY);

    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCurrentPhotoPath)));

    startActivityForResult(intent, CROP);
}
catch (ActivityNotFoundException anfe) {
    String errorMessage = "Your device doesn't support the crop action!";
    Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
    toast.show();
}
于 2013-08-19T06:06:37.297 に答える
0

私はいくつかのクロッパーを試しました。特に、コモンズウェアで参照されているものはあまり整備されていません。たとえば、メタ情報の回転データを使用して撮影された写真は、うまく回転しません。私はこれを見つけました: https://android-arsenal.com/details/1/3487そしてその素晴らしい。注: アクションバー テーマを使用してアクティビティを追加してください。

于 2016-06-22T15:55:56.763 に答える