选择内容里面的ImageView - Android电子 [英] Select Content inside ImageView - Android

查看:125
本文介绍了选择内容里面的ImageView - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动包含的ImageView 我想允许用户选择它的一部分内容与触摸(或点击鼠标)功能。

I have an Activity containing an ImageView and I'd like to allow the User to select part of it's content with the touch (or mouse click) capabilities.

我想写就能实现两件事情的过程:

I'd like to write a procedure able to achieve two things:


  1. 绘制高亮窗口在图像的选定部分

  2. 返回包含所选的(高亮显示)的像素的坐标的对象。

为了更好地理解,你可以检查小模拟了我创建了:

For better understanding you can check the little mock up I've created:

用户应触摸屏在图像的某些部分,它应该得到强调。当pressing后退按钮,我想通过Java来获得被强调像素的坐标。

The User should touch the screen over some part of the image and it should get highlighted. When pressing the back button I'd like to obtain via Java the coordinates of the pixels that were highlighted.

您可以帮助我了解了怎么办?

Can you help me understand how to do?

在我特别想了解以下内容:

In particular I'd like to find out the following:


  1. 我应该访问图像的像素水平的信息?

  2. 这是实现此功能所需的类?

  3. 伪code的一些想法?

Thks任何形式的帮助!

Thks for any kind of help!

推荐答案

我会继承的ImageView ,那么你可以通过覆盖 onTouchEvent捕捉触摸事件(...)

I would subclass ImageView then you can capture the touch events by overriding onTouchEvent(...)

当你到了的onDraw(...)方法,你可以调用超绘制图像正常,然后加上自己的code绘制突出在上面。

When you get to the onDraw(...) method you can call super to draw the image as normal, then add your own code to draw a highlight over the top.

修改

的好,而不是使用的ImageView 你可以扩展它,写自己的类,这一切阶级所要做的就是超越 onTouchEvent(... )让你知道的观点被触摸时,可以在触摸事件的屏幕保存位置。接下来,您编辑的绘图方法:

Well instead of using ImageView you can extend it and write your own class, all this class has to do is override onTouchEvent(...) so you know when the view is being touched and can save the location on screen of the touch events. Next you edit the drawing methods:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas); // So the image you want is drawn as normal

    myMethodForDrawingAFancyHighlight(Canvas canvas); // add your special effects on top of the image
}

这篇关于选择内容里面的ImageView - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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