是否有支持Android图像添加水印的库? [英] Are there any libraries that support Android images to add watermarks?

查看:63
本文介绍了是否有支持Android图像添加水印的库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了很长时间,但并没有得到更好的改善,在不同的手机上:
1.我想在sourceBitmap中添加图片和文字.
2.希望能够调整位图和单词的位置.

I tried for a long time and couldn't get any better,On different mobile phones:
1. I would like to add pictures and words to the sourceBitmap.
2. want to be able to adjust bitmap and word positions.

推荐答案

在不使用库的情况下,我们可以使用画布和绘画概念为图像添加水印

Without using library simply we can watermark image using canvas and paint concept

 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图像添加水印的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆