1

我想在按钮单击时裁剪位图对象,但我希望用手裁剪图像。我找到的所有代码都从相机中获取图像,然后自动裁剪它,但我希望它应该从位图对象中获取图像并且然后手动裁剪?这是我的代码

if(camera!=0)
{
//for camera
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
try {
    intent.putExtra("return-data", true);
    startActivityForResult(intent, camera);
    } catch (ActivityNotFoundException e) {
    // Do nothing for now
    }
}

else
{
    //for gallery``
    intent = new Intent();
    // call android default gallery
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    try {

        intent.putExtra("return-data", true);
        startActivityForResult(Intent.createChooser(intent,
        "Complete action using"), gallery);

        } catch (ActivityNotFoundException e) {
        // Do nothing for now
        }

    }
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try{
    if (requestCode == camera) {
        imageView.setImageBitmap(getBitmapFromIntent(data));
    }

    if (requestCode == gallery) {

    imageView.setImageBitmap(getBitmapFromIntent(data));
    }
        }
       catch(Exception e)
       {
        //do nothing   
       }

private Bitmap getBitmapFromIntent(Intent intent) {

        Uri selectedImage = intent.getData();
        String[] filePathColumn = {MediaStore.Images.Media.DATA};

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

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        filePath = cursor.getString(columnIndex);
        cursor.close();
        options = new BitmapFactory.Options();
        options.inSampleSize = 4;
        photo=(Bitmap)BitmapFactory.decodeFile(filePath,options);
        return BitmapFactory.decodeFile(filePath,options);
}
4

0 回答 0