Skip to content

Instantly share code, notes, and snippets.

@marianoeramirez
Created March 14, 2015 00:00
Show Gist options
  • Save marianoeramirez/b40488139a9f3b1a8c2c to your computer and use it in GitHub Desktop.
Save marianoeramirez/b40488139a9f3b1a8c2c to your computer and use it in GitHub Desktop.
Picasso Rounded upper corner
package com.fundarte.circuitoteatral;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import com.squareup.picasso.Transformation;
public class UpperRoundedTransformation implements Transformation {
private final int radius;
private final int margin; // dp
// radius is corner radii in dp
// margin is the board in dp
public EventoTransformation(final int radius, final int margin) {
this.radius = radius;
this.margin = margin;
}
@Override
public Bitmap transform(final Bitmap source) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);
Rect rectBR = new Rect(0, output.getHeight() / 2, output.getWidth(), output.getHeight());
canvas.drawRect(rectBR, paint);
if (source != output) {
source.recycle();
}
return output;
}
@Override
public String key() {
return "rounded(radius=" + radius + ", margin=" + margin + ")";
}
}
@petersf7
Copy link

petersf7 commented Jul 1, 2015

Works perfectly. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment