简体   繁体   English

Android:在ImageView(或任何其他位图兼容的小部件)上绘制可移动且可调整大小的矩形并裁剪选定的区域

[英]Android: Draw a moveable and sizeable rectangle on ImageView(Or any other bitmap compatible widget) and crop the selected region

I want to crop my image which is being displayed on an ImageView. 我想裁剪我在ImageView上显示的图像。 How I want to go about it is that I want a re-sizable rectangle to be displayed on the image. 我想要的是,我希望在图像上显示一个可调整大小的矩形。 That rectangle will have moveable corners (which I can drag around with touch) to increase/decrease its size. 该矩形将具有可移动的角(我可以通过触摸拖动)来增加/减小其大小。 The image below illustrates a demo of something I would like to develop. 下图说明了我想要开发的一些演示。

PS I am not quite sure how to phrase my question. PS我不太确定如何表达我的问题。 What I want: http://imageshack.us/photo/my-images/832/customcropbox.jpg/ 我想要的是: http//imageshack.us/photo/my-images/832/customcropbox.jpg/

The final solution I came up with after ample research was: 经过充分研究后,我想出的最终解决方案是:

Extend ImageView to make my own custom view. 扩展ImageView以创建我自己的自定义视图。

@Override onDraw method and do my custom drawing there in that method. @Override onDraw方法并在该方法中进行自定义绘图。

Implement onTouchListener on the view to get the touch events and process them according to their position. 在视图上实现onTouchListener以获取触摸事件并根据其位置处理它们。

eg 例如

I checked whether the touch was in the radius of the anchor point circle I drew around the movable rectangle that I was drawing in my overriden onDraw method. 我检查了触摸是否在锚点圆的半径中,我画了我在覆盖onDraw方法中绘制的可移动矩形。

Edit: I am sorry guys I don't have that piece of code anymore, I came here after a very long time otherwise would have loved to help you out. 编辑:我很抱歉,我不再拥有那段代码了,很长一段时间后我来到这里,否则我会很乐意帮助你。

Heartache. 心痛。

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

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