Add watermark on Android using Glide

1

I have the code to add an image in an imageview:

        try {
        Glide.with(imagen.getContext())
                .load(item.getIdImagen())
                //.transform(new GestorImagenes(context, 90f))
                .into(imagen);
    } catch(Exception e) {
    }

I also have the code that would add the watermark:

public Bitmap applyWaterMarkEffect(Bitmap src, String watermark, int x, int y, int color, int alpha, int size, boolean underline) {
    int w = src.getWidth();
    int h = src.getHeight();
    Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());

    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(src, 0, 0, null);

    Paint paint = new Paint();
    paint.setColor(color);
    paint.setAlpha(alpha);
    paint.setTextSize(size);
    paint.setAntiAlias(true);
    paint.setUnderlineText(underline);
    canvas.drawText(watermark, x, y, paint);

    return result;
}

The problem is that I do not know how to combine them to show everything together. Should I take the image (bitmap) to pass it as a parameter? In that case, how do I take it?

Thank you!

    
asked by ZottoSL 05.04.2017 в 22:04
source

1 answer

0

I solved it with the following code:

Glide  
.with(context)
.load(someUrl)
.bitmapTransform(new WatermarkTransformation(context))
.into(imageView);

Within the "WatermarkTransformation" method I put the desired behavior.

    
answered by 07.04.2017 / 00:25
source