i need to extends custom ImageView with linear gradient tranparent. like below image.my input is bitmap data from fresco
. botton 0% opacity and top 100%. can you help me how to?
public class MyImageView extends ImageView (or View) {
....
}
and
myImageView.doIt(myBitmapImageWithoutGradient);
thanks.
UPDATE:
public class GradientImageAlpha extends View {
private Bitmap bitmap;
private Paint paint;
public GradientImageAlpha(Context context) {
super(context);
init();
}
public GradientImageAlpha(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public GradientImageAlpha(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
paint = new Paint();
}
public void inputBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
Shader shaderA = new LinearGradient(0, 0, bitmap.getWidth(), 0, 0xffffffff, 0x00ffffff, Shader.TileMode.CLAMP);
Shader shaderB = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(new ComposeShader(shaderA, shaderB, PorterDuff.Mode.SRC_IN));
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawRect(0, 0, bitmap.getWidth(), bitmap.getHeight(), paint);
}
}