0

我有一个 ImageView,它有一个 Drawable 集作为它的源,它的 scaleType 是 centerCrop。我使用这个 ImageView 作为片段中的背景,我想将它的一个角设置为透明。我找到了一种将角像素设置为透明的方法(https://stackoverflow.com/questions/15228013/skewed-corner-of-imageview-drawable/),但问题是由于我的 Drawable 被 ImageView 缩放,简单地改变源 Drawable 中像素的透明度对我没有好处——根据屏幕尺寸,截断区域要么根本不可见,要么太大。

有没有办法获得在 ImageView 中显示的实际像素,或者我是否必须自己计算缩放后的位图?

4

1 回答 1

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;
    }
于 2013-06-14T04:11:02.593 回答