显示用户照片个人资料来自Facebook质量不佳

时间:2016-09-12 15:41:27

标签: android facebook picasso

我从Facebook获取用户照片个人资料并使用Picasso库来显示图像四舍五入,问题是图像显示的质量很差,我无法很好地看到图像。但在其他应用程序中,例如Tinder等,相同的照片显示得非常好。

这是我的代码:

CircleTransformation transformation;

Picasso.with(this)
        .load(urlImage)
        .placeholder(R.drawable.avatar)
        .resize(50, 50)
        .centerCrop()
        .transform(transformation)
        .into(ivPhoto);


public class CircleTransformation 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.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
        Bitmap bitmap = Bitmap.createBitmap(size, size, config);
        //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/2f;
        canvas.drawCircle(r, r, r, paint);

        squaredBitmap.recycle();
        return bitmap;
    }

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

如何从Facebook正确显示用户照片个人资料?

提前致谢

0 个答案:

没有答案