我有一个ImageView,它有一个Drawable集作为源,其scaleType是centerCrop。我使用此ImageView作为片段中的背景,我想将其中一个角设置为透明。我找到了一种设置角像素透明(https://stackoverflow.com/questions/15228013/skewed-corner-of-imageview-drawable/)的方法,但问题是因为我的Drawable是由ImageView缩放的,只是改变源Drawable中像素的透明度对我没有好处 - 根据屏幕尺寸,截止区域根本不可见或太大。
有没有办法获取ImageView中显示的ACTUAL像素,还是我必须自己计算缩放产生的Bitmap?
答案 0 :(得分:0)
您应该能够使用这些例程将屏幕坐标转换为位图坐标:
/**
* Convert points from screen coordinates to point on image
* @param point screen point
* @param view ImageView
* @return a Point on the image that corresponds to that which was touched
*/
private Point convertPointForView(Point point, ImageView view) {
Point outPoint = new Point();
Matrix inverse = new Matrix();
view.getImageMatrix().invert(inverse);
float[] convertPoint = new float[] {point.x, point.y};
inverse.mapPoints(convertPoint);
outPoint.x = (int)convertPoint[0];
outPoint.y = (int)convertPoint[1];
return outPoint;
}
/**
* Convert a rect from screen coordinates to a rect on the image
* @param rect
* @param view
* @return a rect on the image that corresponds to what is actually shown
*/
private Rect convertRectForView(Rect rect, ImageView view) {
Rect outRect = new Rect();
Matrix inverse = new Matrix();
view.getImageMatrix().invert(inverse);
float[] convertPoints = new float[] {rect.left, rect.top, rect.right, rect.bottom} ;
inverse.mapPoints(convertPoints);
outRect = new Rect((int)convertPoints[0], (int)convertPoints[1], (int)convertPoints[2], (int)convertPoints[3]);
return outRect;
}