User16
User16

Reputation: 39

How to add text watermark on imageview in android,Using this code but not working

How to add text watermark on imageview in android,Using this code but not working

public  Bitmap waterMark(Bitmap src, String watermark, Point location, 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, location.x, location.y, paint);

    return result;
}

And the code is called like this:

Bitmap b=waterMark(BitmapFactory.decodeResource(getResources(), R.drawable.setting),
    R.drawable.image,p, Color.GREEN,90,80,true);
imView.setImageBitmap(b);

Upvotes: 1

Views: 811

Answers (1)

urveshpatel50
urveshpatel50

Reputation: 1685

new Thread(new Runnable() {
            @Override
            public void run() {
                Bitmap b=waterMark(BitmapFactory.decodeResource(getResources(), R.drawable.setting),
                        R.drawable.image,p, Color.GREEN,90,80,true);
                imView.post(new Runnable() {
                    @Override
                    public void run() {
                        imView.setImageBitmap(b);
                    }
                });

            }
        }).start();

Upvotes: 1

Related Questions