android 获取图片上某一个文字位置_android – 如何在ImageView中获取图片的位置?...

我有一个不同大小的图像库.每个图像按顺序显示在

ImageView中(通过OnTouchListener).我需要知道我正在向ImageView显示亲戚的图片框架的位置但是通过我已经完成的测试我只获得了ImageView的坐标.任何的想法?

我需要(x1,y1)和(x2,y2)的值.

提前致谢.

这是我的班级:

public class PuzzleView extends ImageView {

protected Paint currentPaint;

protected boolean drawRect = false;

protected float left;

protected float top;

protected float right;

protected float bottom;

protected float pixelX;

protected float pixelY;

protected int nChunksX = 5;

protected int nChunksY = 5;

protected int currentWidth = 0;

protected int currentHeight = 0;

public PuzzleView(Context context, AttributeSet attrs) {

super(context, attrs);

currentPaint = new Paint();

currentPaint.setDither(true);

currentPaint.setColor(0xFF00CC00);

currentPaint.setStyle(Paint.Style.STROKE);

currentPaint.setStrokeJoin(Paint.Join.ROUND);

currentPaint.setStrokeCap(Paint.Cap.ROUND);

currentPaint.setStrokeWidth(2);

}

@Override

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

float chunkWidth = currentWidth / nChunksX;

float chunkHeight = currentHeight / nChunksY;

float posX = ((int)(pixelX / chunkWidth)) * chunkWidth;

float posY = ((int)(pixelY / chunkHeight)) * chunkHeight;

canvas.drawRect(posX, posY, posX + chunkWidth, posY + chunkHeight, currentPaint);

Rect rect = this.getDrawable().getBounds();

canvas.drawRect(rect, currentPaint);

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

// Get image matrix values and place them in an array

float[] f = new float[9];

getImageMatrix().getValues(f);

// Extract the scale values using the constants (if aspect ratio maintained, scaleX == scaleY)

final float scaleX = f[Matrix.MSCALE_X];

final float scaleY = f[Matrix.MSCALE_Y];

// Get the drawable (could also get the bitmap behind the drawable and getWidth/getHeight)

final Drawable d = getDrawable();

final int origW = d.getIntrinsicWidth();

final int origH = d.getIntrinsicHeight();

// Calculate the actual dimensions

final int actW = Math.round(origW * scaleX);

final int actH = Math.round(origH * scaleY);

currentWidth = actW;

currentHeight = actH;

}

public boolean isDrawRect() {

return drawRect;

}

public void setDrawRect(boolean drawRect) {

this.drawRect = drawRect;

}

public float getLeftRect() {

return left;

}

public void setLeftRect(float left) {

this.left = left;

}

public float getTopRect() {

return top;

}

public void setTopRect(float top) {

this.top = top;

}

public float getRightRect() {

return right;

}

public void setRightRect(float right) {

this.right = right;

}

public float getBottomRect() {

return bottom;

}

public void setBottomRect(float bottom) {

this.bottom = bottom;

}

public float getPixelX() {

return pixelX;

}

public void setPixelX(float pixelX) {

this.pixelX = pixelX;

}

public float getPixelY() {

return pixelY;

}

public void setPixelY(float pixelY) {

this.pixelY = pixelY;

}

public int getChunksX() {

return nChunksX;

}

public void setChunksX(int nChunksX) {

this.nChunksX = nChunksX;

}

public int getChunksY() {

return nChunksY;

}

public void setChunksY(int nChunksY) {

this.nChunksY = nChunksY;

}

}

目前,源图像在XML文件中定义:

android:id="@+id/imageViewSelected"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:contentDescription="@string/image_selected"

android:src="@android:drawable/progress_indeterminate_horizontal" />

我需要在图像上画一个网格.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值