如何在Android中创建像QuickPic应用程序的裁剪工具?

时间:2014-12-04 14:28:38

标签: android android-canvas android-imageview crop pinchzoom

如何在android中创建像QuickPic app这样的裁剪工具,我们可以移动和缩放要裁剪的图像?

我们需要能够移动图像以及裁剪框。我们需要使用canvas来实现它吗?

或者我们可以在另一个上移动一个物体吗?关于如何开始的任何建议或链接都​​将受到赞扬。

我使用过android-crop库但没有得到我想要达到的目的。

1 个答案:

答案 0 :(得分:1)

您可以使用相机Intent Cropping操作。如果用户设备不支持裁剪Intent,则会看到错误消息。在“try”块中,按如下方式启动Intent:

        //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", 1);
cropIntent.putExtra("aspectY", 1);
    //indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
    //retrieve data on return
cropIntent.putExtra("return-data", true);
    //start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);

You can refer to this link for more details.