开发者

Point in Matrix coordinates

开发者 https://www.devze.com 2023-03-01 05:38 出处:网络
Is it possible to check if a point is contained in a Matrix coordinates? I have the original Matrix used to draw a View and want to know if the onTouch event coordinates are included in its coordinate

Is it possible to check if a point is contained in a Matrix coordinates? I have the original Matrix used to draw a View and want to know if the onTouch event coordinates are included in its coordinates. Thanks


Ok, I should explain better. I have a custom View MyView. In its constructor i pass the matrix to draw the view. The onDraw method is:

@Override   
protected void onDraw(Canvas canvas) {  
         super.onDraw(canvas);
         canvas.drawBitmap(this.baseBitmap, this.matrix, null); 
}

In the onTouch method i can get the touched point with event.getX() and event.getY() and using these, i need to check if the touched point is inside开发者_Python百科 MyView.

Hope it's clear now :)


I used the following code to calculate the (x4,y4) coordinates of a matrix.

float[] matrixValues = new float[9];
matrix.getValues(matrixValues);
view.getDrawable().getIntrinsicHeight() * matrixValues [0]; 
view.getDrawable().getIntrinsicWeight() * matrixValues [0];

Because of the layer management, perapse you have to use the following methode to check the ImageView coordinates :

yourImageView.getTop()
yourImageView.getBottom()
yourImageView.getRight()
yourImageView.getLeft()

e.g.

float[] m = new float[9];
matrix.getValues(m);
int layoutHeight = view.getBottom() - view.getTop();
float maxMatrixBottomPosition = - ((view.getDrawable().getIntrinsicHeight() * m[0]) - layoutHeight);


float[] values = new float[9];
matrix.getValues(values);
globalX = values[2];
globalY = values[5];

here globalx and globaly will give the x and y co-ordinates of the your view and then compare it with the event.getX and event.getY values

0

精彩评论

暂无评论...
验证码 换一张
取 消