我试了很久都没有好转,在不同的手机上:
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/