Android Piccaso与图像周围的红色圆形边框

时间:2017-05-04 03:40:23

标签: android

我正在使用Piccaso库来制作圆形图像但不知何故我无法添加红色圆形边框的图像。我在Tranform类下面使用它来执行它:

ublic class RedCircleTransform implements Transformation {
        int mBorderSize;

        @Override
        public Bitmap transform(Bitmap source) {
            int size = Math.min(source.getWidth(), source.getHeight());

            int x = (source.getWidth() - size) / 2;
            int y = (source.getHeight() - size) / 2;

            Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
            if (squaredBitmap != source) {
                source.recycle();
            }

            Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            BitmapShader shader = new BitmapShader(squaredBitmap,
                    BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
            paint.setShader(shader);
        paint.setStrokeWidth(10);
            paint.setColor(Color.RED);
            paint.setAntiAlias(true);

            float r = size / 2f;
            canvas.drawCircle(r, r, r, paint);

            squaredBitmap.recycle();
            return bitmap;
        }

        @Override
        public String key() {
            return "circle";
        }
}

2 个答案:

答案 0 :(得分:2)

您可以使用Lopez Mikhael

之前的CircularImageView

<强>摇篮

 compile 'com.mikhaellopez:circularimageview:3.0.2'

<强> XML

<com.mikhaellopez.circularimageview.CircularImageView
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:src="@drawable/image"
        app:civ_border_color="#EEEEEE"
        app:civ_border_width="4dp"
        app:civ_shadow="true"
        app:civ_shadow_radius="10"
        app:civ_shadow_color="#8BC34A"/>

答案 1 :(得分:0)

将此依赖关系用于圆形图像视图,它还包括其他类型的图像视图。

将此行添加到您的依赖项

compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'

以XML格式

<com.github.siyamed.shapeimageview.CircularImageView
        android:id="@+id/android_gridview_image"
        android:layout_width="75dp"
        android:layout_height="65dp"
        app:siBorderColor="#fff"
        android:layout_marginTop="15dp" />