我想修复矩形大小,同时在android中裁剪图像

时间:2014-07-21 11:53:56

标签: android image crop

我想在裁剪图像时修复矩形大小。我该怎么做任何帮助将不胜感激。我当前的代码看起来如下所示。

 // call android default gallery
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
 // ******** code for crop image
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 150);
intent.putExtra("scale", true);
intent.putExtra("scaleUpIfNeeded", true);

intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

2 个答案:

答案 0 :(得分:1)

这可能会对您有所帮助,请使用此代码...

    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", 3);
    intent.putExtra("aspectY", 2);
    intent.putExtra("scale", true);
    intent.putExtra("image-path", root);

答案 1 :(得分:0)

试试这个

private void performCrop(Uri picUri,int responseCode,int xRation,int yRation) {
        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(picUri, "image/*");
            // set crop properties
            cropIntent.putExtra("crop", "true");
            // indicate aspect of desired crop
            cropIntent.putExtra("aspectX", xRation);
            cropIntent.putExtra("aspectY", yRation);
            // indicate output X and Y
//          cropIntent.putExtra("outputX", 256);
//          cropIntent.putExtra("outputY", 256);
            // retrieve data on return
            cropIntent.putExtra("return-data", false);
            File f = createNewFile("CROP_");
            try {
                f.createNewFile();
            } catch (IOException ex) {
            }
            Uri mCropImagedUri = Uri.fromFile(f);
            cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCropImagedUri);
            // start the activity - we handle returning in onActivityResult
            startActivityForResult(cropIntent, responseCode);
        } catch (ActivityNotFoundException e) {

        }
    }