如何做才能让你在Android的裁剪图像可调整大小的矩形? [英] How do you make a resizable rectangle for cropping images in android?

查看:182
本文介绍了如何做才能让你在Android的裁剪图像可调整大小的矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要裁剪我正在被显示在一个的ImageView 图像。我想怎么去了解它,我想重新相当大的矩形要在图像上显示。该矩形将有可移动的角落(我可以触摸拖动)增加/减少它的大小。 下图说明了东西,我想开发一个演示。

I want to crop my image which is being displayed on an 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.

推荐答案

至于你的问题很模糊这里是一些通过创建自己的视图来解决这个普遍的做法。我建议你​​用自己的类扩展的机器人ImageView的。

As your question is very vague here is some general approach to solve this by creating an own View. I would suggest you extend the Androids ImageView with your own class.

在这个类,你可以使用

public void draw(Canvas canvas)

方法绘制像一个矩形或圆形的边角附加元素(不要忘记调用super.draw使图像也被绘制。

method to draw additional elements like a rectangular or circles for the corners (don't forget to call super.draw so that the image is also drawn.

此外,你要截取该视图的UI事件,以决定是否一个角落移动用户。请参见 http://developer.android.com/guide/topics/ui/ UI-events.html 了解关于它的更多细节。

Furthermore, you have to intercept the UI events on that view to decide if a corner was moved by the user. See http://developer.android.com/guide/topics/ui/ui-events.html for more details on that.

在你的布局你可以用你的包和视图类的标签名称的XML标记添加了这一观点。例如:

Within your layout you can add this view just by an XML tag with your package and view class as tag name. e.g.:

<com.example.MyCustomView android:layout_height="fill_parent" android:layout_width="fill_parent" android:src="@drawable/myImage"/>

这篇关于如何做才能让你在Android的裁剪图像可调整大小的矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆