有没有支持Android图片添加水印的库?

zha*_*gle 1 android bitmap

我尝试了很长时间也没有更好的办法,在不同的手机上:
1.我想在sourceBitmap中添加图片和文字。
2.希望能够调整位图和字的位置。

sas*_*mar 5

无需使用库,我们就可以使用画布和绘画概念为图像添加水印

 Point point=new Point();
 point.set(180, 1000);
 Bitmap b=waterMark(BitmapFactory.decodeResource(getResources(), R.drawable.image),"your Text",point,Color.WHITE,90,30,true);
 imageView.setImageBitmap(b);
Run Code Online (Sandbox Code Playgroud)

方法代码

public  Bitmap waterMark(Bitmap src, String watermark, Point location, int color, int alpha, int size, boolean underline) {
 //get source image width and height
 int w = src.getWidth();
 int h = src.getHeight();

 Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
 //create canvas object
 Canvas canvas = new Canvas(result);
 //draw bitmap on canvas
 canvas.drawBitmap(src, 0, 0, null);
 //create paint object
 Paint paint = new Paint();
 //apply color
 paint.setColor(color);
 //set transparency
 paint.setAlpha(alpha);
 //set text size
 paint.setTextSize(size);
 paint.setAntiAlias(true);
 //set should be underlined or not
 paint.setUnderlineText(underline);
 //draw text on given location
  canvas.drawText(watermark, location.x, location.y, paint); 
 return result;
}
Run Code Online (Sandbox Code Playgroud)