Android应用中裁剪正方形图像的形状

7

我希望创建一个应用程序,允许用户将图像调整为正方形(长度等于宽度)。

我知道可以使用图库以以下方式进行操作:

private void crop(Uri photoUri) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setData(photoUri);
    intent.putExtra("outputX", 200);
    intent.putExtra("outputY", 200);
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, RESULT_CROP);
}

我想知道是否有一个库可以直接在应用程序中完成这个操作?谢谢!

请使用链接中的代码进行裁剪。这不需要使用任何库。http://www.androidhub4you.com/2012/07/how-to-crop-image-from-camera-and.html - Raghunandan
感谢@Raghunandan,但这并不完全是我想要的。 - lopez.mikhael
2个回答

12
我在这里找到了我的解决方案(链接),但我接受其他答案!!

裁剪工具


有没有其他的选择?我想要从头开始实现它...我想在捕获过程中裁剪图像,而不是之后再进行裁剪。 - pritam001

0

我使用了这个库https://arthurhub.github.io/Android-Image-Cropper/

除此之外,您还需要在示例项目中查看示例代码,并修复宽高比并将缩放比例设置为1。

cropImageView.setFixedAspectRatio(true);
cropImageView.setScaleX(1.0f);
cropImageView.setScaleY(1.0f);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接