1

ユーザーが画像をトリミングするための次のコードがあります。256 を超えるサイズを設定すると動作しません。私の直感は「cropIntent.putExtra("return-data", true);」です。エラーの原因。uri を cropIIIntent に渡し、onActivityResults から取得するにはどうすればよいですか? つまり、トリミングして取得した後に画像を保存します。

private void performCrop() {
    try {
        //call the standard crop action intent (the user device may not support it)
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        //indicate image type and Uri
        cropIntent.setDataAndType(mImageCaptureUri, "image/*");
        //set crop properties
        cropIntent.putExtra("crop", "true");
        //indicate aspect of desired crop
        cropIntent.putExtra("aspectX", 4);
        cropIntent.putExtra("aspectY", 3);
        //indicate output X and Y
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        //retrieve data on return
        cropIntent.putExtra("return-data", true);

        startActivityForResult(cropIntent, PIC_CROP);

    } //respond to users whose devices do not support the crop action
    catch (ActivityNotFoundException anfe) {
        //display an error message
        String errorMessage = "Your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
}

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

         if (requestCode == PIC_CROP) {
            try {
               final TextView imgTv = (TextView) findViewById(R.id.imageInfo);
                Bundle extras = data.getExtras();
                thumbnail = extras.getParcelable("data");
                ImageView image = (ImageView) findViewById(R.id.pestImage);
                image.setImageBitmap(thumbnail);
        File f = new File(mImageCaptureUri.getPath());
        if (f.exists()) {
            f.delete();
        }
    }
}//end onactivity results
4

3 に答える 3

0

試す

    Uri cropedImageUri = data.getData();

String[] filePathColumn = { MediaStore.Images.Media.DATA };

                Cursor cursor = getContentResolver().query(cropedImage,
                        filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String filePath = cursor.getString(columnIndex);
                cursor.close();

現在、filePath はトリミングされた画像へのパスです

filePath からビットマップをロードするには

 private Bitmap loadImageFromSDCard(String filePath) {

        BitmapFactory.Options bfo = new BitmapFactory.Options();
        bfo.inSampleSize = 1;
        bfo.outWidth = 100;
        bfo.outHeight = 100;
        Bitmap photo = BitmapFactory.decodeFile(filePath, bfo);
        return photo;
    } 
于 2013-04-04T09:58:40.457 に答える
0
    if (android.os.Build.VERSION.SDK_INT > 10){
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        cropIntent.setDataAndType(picUri, "image/*");
        cropIntent.putExtra("crop", "true");
        int gcd = BigInteger.valueOf(ImageWidth).
              gcd(BigInteger.valueOf(ImageHeight)).intValue();
        cropIntent.putExtra("aspectX", (ImageWidth / gcd));
        cropIntent.putExtra("aspectY", (ImageHeight / gcd));
        cropIntent.putExtra("outputX", ImageWidth);  // X
        cropIntent.putExtra("outputY", ImageHeight);  // Y
        cropIntent.putExtra("return-data", true);
        cropIntent.setData(picUri);
        startActivityForResult(cropIntent, PIC_CROP_INTENT_ID);
    }
于 2014-12-22T09:41:37.370 に答える