我有一個函數,它將一個位圖作爲參數,並返回一個位圖。Picasso自定義位圖變換方法
public Bitmap setRoundedCornes(Bitmap b, int l, int r, int t, int b)
使用畢加索之前,我用這個方法在應用程序中使用我的最後位之前。
現在我正在使用畢加索,我不確定如何應用此方法。
有沒有人有任何想法?
編輯
我現在有:
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int topLeftX, int topLeftY, int topRightX, int topRightY, int bottomRightX, int bottomRightY, int bottomLeftX, int bottomLeftY) {
try {
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
// the float array passed to this function defines the x/y values of the corners
// it starts top-left and works clockwise
// so top-left-x, top-left-y, top-right-x etc
RoundRectShape rrs = new RoundRectShape(new float[]{topLeftX, topLeftY, topRightX, topRightY, bottomRightX, bottomRightY, bottomLeftX, bottomLeftY}, null, null);
canvas.drawARGB(0, 0, 0, 0);
paint.setAntiAlias(true);
paint.setColor(0xFF000000);
rrs.resize(bitmap.getWidth(), bitmap.getHeight());
rrs.draw(canvas, paint);
paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}catch(Exception e){
return bitmap;
}
}
和
public class MyTransform implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
//your logic to transform goes here
return getRoundedCornerBitmap(source, 20, 20, 20, 20, 0, 0, 0, 0);
}
@Override
public String key() {
return "circle";
}
}
'key()'在哪裏使用? –
來自文檔\t'key() 返回轉換的唯一鍵,用於緩存目的。' –
https://square.github.io/picasso/javadoc/com/squareup/picasso/Transformation.html –