修复Android中图像裁剪的正方形

Posted

技术标签:

【中文标题】修复Android中图像裁剪的正方形【英文标题】:Fix square for image cropping in Android 【发布时间】:2014-12-20 16:03:46 【问题描述】:

我正在开发一个 android 应用程序,我想在其中修复用于裁剪的正方形比例。我的代码如下:

public void cropCapturedImage(Uri picUri)
        //call the standard crop action intent 
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        //indicate image type and Uri of image
        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", 512);
        cropIntent.putExtra("outputY", 512);
        //retrieve data on return
        cropIntent.putExtra("return-data", true);
        //start the activity - we handle returning in onActivityResult
        startActivityForResult(cropIntent, 2);
    

【问题讨论】:

【参考方案1】:

Android does not have CROP Intent。没有要求任何设备都有一个应用程序来支持您未记录和不受支持的 Intent 操作,更不用说特定的附加功能组合了。

作为we discussed previously,有许多适用于Android 的图像裁剪库。至少one 支持方形裁剪,还有at least one fork of that library 提供对裁剪区域大小的固定控制。 the available image cropping libraries 的其他库可能提供类似的功能,如果您不喜欢其中任何一个,欢迎您派生其中一个库或从头开始编写自己的库。

此外,请记住,并非所有设备的两个轴都有 512 像素,因此并非用户无法轻松裁剪 512x512 图像。

【讨论】:

以上是关于修复Android中图像裁剪的正方形的主要内容,如果未能解决你的问题,请参考以下文章

我如何在android中裁剪像scanmaster.apk这样的图像

在Android中以给定的正方形大小裁剪图像?

Edmodo android图像裁剪器,修复纵横比

在 Android 中使用 FFmpeg 将视频裁剪为方形格式

裁剪和旋转图片 OpenCV

OpenCV 裁剪函数致命信号 11