简体   繁体   English

修复正方形以在Android中进行图像裁剪

[英]Fix square for image cropping in Android

I am working on an Android application in which I want to fix the ratio of square used for cropping. 我正在开发一个Android应用程序,其中我要固定用于裁剪的平方比。 My code is given below: 我的代码如下:

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);
    }

Android does not have CROP Intent . Android没有CROP Intent There is no requirement that any device have an app that honors your undocumented and unsupported Intent action, let alone that particular mix of extras. 无需任何设备都具有能够兑现您未记录且不受支持的Intent操作的应用程序,更不用说这些额外的功能了。

As we discussed previously , there are many image cropping libraries available for Android. 正如我们之前讨论的 ,Android有许多图像裁剪库。 At least one supports square cropping, and there is at least one fork of that library that offers fixed control over the size of the crop area. 至少有一个支持方形裁剪,并且该库至少有一个叉子可以对裁剪区域的大小进行固定控制。 Others of the available image cropping libraries may offer similar features, and if you do not like any of those, you are welcome to fork one of those libraries or write your own from scratch. 其他可用的图像裁剪库可能提供相似的功能,如果您不喜欢其中任何一个,欢迎您分叉其中一个库或从头开始编写自己的库。

Also, bear in mind that not all devices have 512 pixels along both axes, and so not users may not be able to crop a 512x512 image very readily. 另外,请记住,并非所有设备的两个轴都具有512像素,因此用户可能无法非常容易地裁剪512x512图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM