Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 编辑图像视图';s像素到位_Android - Fatal编程技术网

Android 编辑图像视图';s像素到位

Android 编辑图像视图';s像素到位,android,Android,我有一个ImageView,它的源是一个可绘制集,其scaleType是centerCrop。我使用这个ImageView作为片段的背景,我想将它的一个角设置为透明。我找到了一种将角点像素设置为透明的方法(),但问题是,由于我的可绘制区域是由ImageView缩放的,因此简单地更改源可绘制区域中像素的透明度对我没有好处——取决于屏幕大小,截止区域要么根本不可见,要么太大 有没有办法获取ImageView中显示的实际像素,或者我需要自己计算缩放后的位图?您应该能够使用这些例程将屏幕坐标转换为位图坐

我有一个ImageView,它的源是一个可绘制集,其scaleType是centerCrop。我使用这个ImageView作为片段的背景,我想将它的一个角设置为透明。我找到了一种将角点像素设置为透明的方法(),但问题是,由于我的可绘制区域是由ImageView缩放的,因此简单地更改源可绘制区域中像素的透明度对我没有好处——取决于屏幕大小,截止区域要么根本不可见,要么太大


有没有办法获取ImageView中显示的实际像素,或者我需要自己计算缩放后的位图?

您应该能够使用这些例程将屏幕坐标转换为位图坐标:

 /**
     * 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;
    }

这似乎对我不起作用。看起来这适用于拉伸的图像,但是,我的缩放类型是centerCrop。