Imageview Roundcorner不适用于所有四个角落

时间:2016-02-16 06:53:09

标签: android android-imageview picasso android-bitmap

enter image description here

我尝试使用圆角进行图像查看。但我面临一些问题。我不能为所有四个方面制作圆角。我试过这段代码
Imageviewclass.class Picasso.with(con).load(itemsArrayList.get(position).get("item_image")).transform(new Resizeimageview()).into(holder.img);

ResizeImageview.class

public class Resizeimageview implements Transformation {
    @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, source.getConfig());

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

        float r = size / 8f;
        canvas.drawRoundRect(new RectF(0, 0, source.getWidth(), source.getHeight()), r, r, paint);
        squaredBitmap.recycle();
        return bitmap;
    }

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

2 个答案:

答案 0 :(得分:2)

尝试替换此行

canvas.drawRoundRect(new RectF(0, 0, source.getWidth(), source.getHeight()), r, r, paint);

用这个

canvas.drawRoundRect(new RectF(0, 0, size, size), r, r, paint);

答案 1 :(得分:0)

试试这个:

Download the Universal Image Loader from the given link : 

https://github.com/nostra13/Android-Universal-Image-Loader/wiki/Quick-Setup

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            context).build();
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config);

DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(250)).cacheOnDisc().build();

ImageLoader.getInstance().displayImage(itemsArrayList.get(position).get("item_image"), holder.img, options);