Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add watermark image in android

I have code to add watermark in image like this

public static Bitmap mark(Bitmap src, String watermark, Point location, Color 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.RED);
            paint.setAlpha(alpha);
            paint.setTextSize(size);
            paint.setAntiAlias(true);
            paint.setUnderlineText(underline);
            canvas.drawText(watermark, location.x, location.y, paint);

            return result;
        }

and I call that function with this code

mark(bitmap, "watermark", b, null, c, 100, false);
            imgshoot.setImageBitmap(bitmap);

but nothing happen , can u help me ?? thanks

like image 861
ya Lya Avatar asked Nov 07 '12 09:11

ya Lya


1 Answers

it solved , I just change little for that code , and thanks for ur advice Doomsknight :)

 public static Bitmap mark(Bitmap src, String watermark) {
    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.RED);
    paint.setTextSize(18);
    paint.setAntiAlias(true);
    paint.setUnderlineText(true);
    canvas.drawText(watermark, 20, 25, paint);

    return result;
}

and I call with this function

bitmap = mark(bitmap, "Hallo");
imgshoot.setImageBitmap(bitmap);
like image 199
ya Lya Avatar answered Nov 15 '22 06:11

ya Lya