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

标签 android bitmap

我试了很久都没有好转,在不同的手机上:
1.我想在sourceBitmap中添加图片和文字。
2.希望能够调整位图和字的位置。

最佳答案

不使用库,我们可以简单地使用 Canvas 和绘画概念为图像加水印

 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);

方法代码

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;
}

关于android - 有没有支持Android图片加水印的库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44939748/

相关文章:

C++ Win32,用位图显示窗口的最简单方法

android - 无法保存位图图像

Android 如何使用 BitmapFactory 选项缩放图像

vb.net - 将 png 图片设为透明

背景为黑色时,Android PorterDuff.Mode.CLEAR 无法正常工作

android - 如何导航到相同的父状态

android - 已编译的 apk 正在尝试访问 metor 服务器 react native

android - AppcompatActivity:OutMemoryException

Android 处理 TextView 中的 HTML 链接和键入的链接

c - 写入位图 24 位颜色奇怪的行为