Android实现为图片添加水印
程序员文章站
2023-12-20 08:19:16
添加水印的方法挺简单的,具体内容如下
public class mainactivity extends appcompatactivity {
@ov...
添加水印的方法挺简单的,具体内容如下
public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); imageview iv = (imageview) findviewbyid(r.id.imageview); drawable drawable = contextcompat.getdrawable(this, r.drawable.image); bitmapdrawable bd = (bitmapdrawable) drawable; bitmap bmp = bd.getbitmap(); bitmap bitmap = createwatermark(bmp, "叶应是叶" + "http://blog.csdn.net/new_one_object"); iv.setimagebitmap(bitmap); } private bitmap createwatermark(bitmap bitmap, string mark) { int w = bitmap.getwidth(); int h = bitmap.getheight(); bitmap bmp = bitmap.createbitmap(w, h, bitmap.config.argb_8888); canvas canvas = new canvas(bmp); paint p = new paint(); // 水印颜色 p.setcolor(color.parsecolor("#c5576370")); // 水印字体大小 p.settextsize(150); //抗锯齿 p.setantialias(true); //绘制图像 canvas.drawbitmap(bitmap, 0, 0, p); //绘制文字 canvas.drawtext(mark, 0, h / 2, p); canvas.save(canvas.all_save_flag); canvas.restore(); return bmp; } }
效果图
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。