Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.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
Java 如何将阴影添加到裁剪的圆形图像中?_Java_Android_Image_Android Image_Android Imagebutton - Fatal编程技术网

Java 如何将阴影添加到裁剪的圆形图像中?

Java 如何将阴影添加到裁剪的圆形图像中?,java,android,image,android-image,android-imagebutton,Java,Android,Image,Android Image,Android Imagebutton,我使用下面的方法将图像转换为圆形。(其目的是在Android应用程序中使用圆形图像作为按钮。) 我想增加一点阴影,但我没法让它起作用。有人能帮忙吗 public static class CircleTransform extends BitmapTransformation { public CircleTransform(Context context) { super(context); } @Override protected Bitm

我使用下面的方法将图像转换为圆形。(其目的是在Android应用程序中使用圆形图像作为按钮。)

我想增加一点阴影,但我没法让它起作用。有人能帮忙吗

public static class CircleTransform extends BitmapTransformation {
    public CircleTransform(Context context) {
        super(context);
    }

    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
        return circleCrop(pool, toTransform);
    }

    private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
        if (source == null) return null;
        int size = Math.min(source.getWidth(), source.getHeight());
        int x = (source.getWidth() - size) / 2;
        int y = (source.getHeight() - size) / 2;
        Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
        Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
        if (result == null) {
            result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        }
        Canvas canvas = new Canvas(result);
        Paint paint = new Paint();
        paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
        paint.setAntiAlias(true);
        float r = size / 2f;
        canvas.drawCircle(r, r, r, paint);
        return result;
    }

    @Override
    public String getId() {
        return getClass().getName();
    }
}