如何从android中的图像裁剪矩形

时间:2012-02-14 19:18:14

标签: android

我正在使用this示例裁剪从图库中选择的图像,但问题是该示例仅裁剪正方形。是否可以裁剪矩形而不仅仅是正方形?在该示例中,如果我移动一侧,则相邻侧移动,使其保持正方形选择。

感谢。

2 个答案:

答案 0 :(得分:12)

我发现可以使用内置的Android裁剪处理程序裁剪矩形。(com.android.camera.action.CROP)。要裁剪矩形,您需要删除我之前传递的示例的以下参数:

intent.putExtra("outputX", 200); //Set this to define the max size of the output bitmap
intent.putExtra("outputY", 200); //Set this to define the max size of the output bitmap
intent.putExtra("aspectX", 1); //Set this to define the X aspect ratio of the shape
intent.putExtra("aspectY", 1); //Set this to define the Y aspect ratio of the shape

当你移动其中一个时,设置aspectX和aspectY将强制android移动形状的两侧。评论这些线条,你就可以随意移动形状。

答案 1 :(得分:3)

使用内置Android裁剪无法裁剪为方形以外的任何其他内容 处理(com.android.camera.action.CROP)。

您必须从头开始构建自己的裁剪活动。您可能希望将自己的实现基于implementation from the SDK(需要GIT)。

在Stack Overflow等Q& A网站上简单回答,讨论复杂的任务细节是不可能的。如果您有特殊问题,请不要犹豫,发布另一个问题。